How to find matrix values by column and row indexes
3 次查看(过去 30 天)
显示 更早的评论
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. :)
0 个评论
回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!