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일

2 개 추천

out=A(A>45)
If you want the location:
idx=find(A>45) % corresponding indices
out=A(idx)

댓글 수: 3

Ede gerlderlands
Ede gerlderlands 2013년 7월 15일
This gives me the total values. What I want is the position(location) of values which are greater than 45. The locationhas to be with respect to the column ex. for column 1, 5, 65 ,78 etc... for column two 4, 5,8,12,...
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일

1 개 추천

[i,j]=find(A>45);

댓글 수: 7

Ede gerlderlands
Ede gerlderlands 2013년 7월 15일
I think am not clear with you. Is it not possible to get the location per co;umn? this gives me the over all location? isn't that? tnx
Matt J
Matt J 2013년 7월 15일
편집: Matt J 2013년 7월 15일
Show us the desired output for this small example matrix
A=[0 46 10 1; 47 5 48 5; 3 19 25 70]
And explain what form the output should take (cell, matrix, structure, etc...)
Ede gerlderlands
Ede gerlderlands 2013년 7월 15일
The answer will be 2 for the first column 1 and 3 foe the second as well as 4 for the third column. the output should be in str. Thank you
Matt J
Matt J 2013년 7월 15일
The example matrix I gave you has 4 columns...
Ede gerlderlands
Ede gerlderlands 2013년 7월 15일
sorry, it has to be rows
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일

0 개 추천

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.

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2013년 7월 15일

댓글:

2020년 5월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by