フィルターのクリア

How to find matrix values by column and row indexes

4 ビュー (過去 30 日間)
m h
m h 2021 年 2 月 5 日
編集済み: m h 2021 年 2 月 8 日
Hi,
I have a large m x n matrix, let's say "A" and I would like to find the location indexes of minimum values(negative or positive) in each column and confirm that location. So, I used sth like this
>> temp0=A
>> temp1=abs(A)
>> sorted_mat=sort(temp1,1,'ascend');
>> [rw0, col0]=find(temp1==sorted_mat(1,:));
>> For i=1:size(rw0,1)
>> min_values(i)=temp0(rw0(i),col0(i))
>> end
However, I would like to use indexes directly. I had this method
>> temp0=A
>> temp1=abs(A)
>> sorted_mat=sort(temp1,1,'ascend');
>> [rw0, col0]=find(temp1==sorted_mat(1,:));
>> min_values=nonzeros(A(rw0,col0).*eye(size(rw0,1))
The problem with this method is that it doesn't work with really large numbers like 60k. Do you have any idea to solve it by indexes? I don't like using for loops. :)

回答 (1 件)

Sourabh Kondapaka
Sourabh Kondapaka 2021 年 2 月 8 日
編集済み: Sourabh Kondapaka 2021 年 2 月 8 日
Hi @m h,
You can find min-values in a matrix either column-wise or row-wise without using loops. Please check the documentation for the "min()" function.
You can find similar questions answered in this community:
  1 件のコメント
m h
m h 2021 年 2 月 8 日
編集済み: m h 2021 年 2 月 8 日
Hi,
Actually, I am not looking for min or max values in my matrix. What I am looking for is, the closest point to certain point that changes in time in 1D environment. If the closest point is behind the target point, it will have negative values or vice versa. So, the minimum values above indicates closest point, not the minimum values in my matrix. I can write code with minimum function like
>> temp0=A
>> temp1=abs(A)
>>[Mx idx]=min(temp1,[],1]
>>[Mx idy]=min(temp1,[],2]
>> For i=1:size(idx,1)
>> searched_values(i)=temp0(idx(i),idy(i))
>> end
My question is whether there is a way to express something like below
->> searched_values=temp0(idx,idy) (this doesn't work)
( searched_values=nonzeros(A(rw0,col0).*eye(size(rw0,1)) % I had this but it doesn't work due to matrix size.)
instead of for loop.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

製品


リリース

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by