How may I use the find function to search a range or rows and a specific column please?
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Isi Isi
am 3 Jan. 2017
Beantwortet: Roger Stafford
am 3 Jan. 2017
Hey guys, so basically I'm trying to use the 'find' function in matlab to search a range of rows and a particular column in an array for the indices of elements that have a value of 7. So basically what I did was:
X=zeros(4,5);
X(1:3,4)=7;
[A,B] = find( X( 1:3,4) == 7 );
What the code is meant to do is search rows 1:3 of column 4 for elements with a value of seven and save the indices of these elements to A(i.e. rows) and B(i.e. columns). A works out fine as I get the values 1,2,3 stored in A but the values gotten in B are 1,1,1. Any idea of what I may be doing wrong please? I know I could achieve this using a for loop but I do not want to as this made my code really slow. Thanks
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 3 Jan. 2017
You are applying find to a 3 x 1 vector, and asking for row and column outputs. Since the vector is only one column wide, the output is always going to reflect column 1.
If you want to search a subarray X(J:K, P:Q)
[A,B] = find(X(J:K, P:Q) == 7)
but you want to get back indices relative to the original array, then you need A + J + 1 and B + P - 1
0 Kommentare
Weitere Antworten (1)
Roger Stafford
am 3 Jan. 2017
The 'B' values are the column indices of the matrix X(1:3,4), and relative to this matrix those column numbers are all ones.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!