finding values from matrix

706 ビュー (過去 30 日間)
Ede gerlderlands
Ede gerlderlands 2013 年 7 月 15 日
Dear All
I have a matrix which is given by A= [20 140]. I want to find the location of elements in A which are greter than 45. Here is the matlab script which I tried to work upon but it gives me the whole value rather than location with respect to each coumn.
for i = 1:20
Loc(ii,:)= find(A(i,:)>45);
end
Thank you for your help

回答 (3 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 7 月 15 日
編集済み: Azzi Abdelmalek 2013 年 7 月 15 日
out=A(A>45)
If you want the location:
idx=find(A>45) % corresponding indices
out=A(idx)
  3 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 7 月 15 日
Ok
A=randi(200,5) % Example
[ii,jj]=find(A>45)
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 7 月 15 日
編集済み: Azzi Abdelmalek 2013 年 7 月 15 日
A=[0 46 10 1; 47 5 48 5; 3 19 25 70]
out=arrayfun(@(x) max(find(A(x,:)>45)),1:size(A,1))

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


Matt J
Matt J 2013 年 7 月 15 日
[i,j]=find(A>45);
  7 件のコメント
Matt J
Matt J 2013 年 7 月 15 日
for k=1:size(A,1)
S(k).locs = find(A(k,:)>45);
end
Edwin Herrera Vasco
Edwin Herrera Vasco 2020 年 5 月 4 日
Thanks!!!

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


Iain
Iain 2013 年 7 月 15 日
A = [45 46; 42 43];
logical_address = A>45;
A(logical_address) %gives you a single 46.
linear_index = find(logical_address);
A(linear_index) % gives you a single 46.
[rowno, colno ] = sub2ind(size(A),linear_index);
A(rowno,colno ) % gives you a single 46
Looking at your code, I think you're trying to do that row by row.
find(A(i,:)>45) will give a vector containing the column number of each column which is >45 in that row of A - the length of this may vary from row to row, so you can't store the result in a simple vector - you'd need to use a cell array.

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by