Extracting the values using [row,col]

4 views (last 30 days)
I have successfully found the row and col's in "x" , (a 61x61 double) where the x values in a line match with values in "x".
%rows and columns where the xvalues of the line are the values in x(contour lines)
[row,col] = find(ismembertol(x,xvalues));
Now, I want to use the subscripts/values in [row,col] to extract data for corresponding cells in any other double.
For example, here are five random locations/indexes in my [row,col].
5 31
20 34
61 47
45 59
23 61
I want to find the 5th row and 31st column in z and y.
20th row and 24th column in z and y... etc

Accepted Answer

Walter Roberson
Walter Roberson on 4 Jun 2019
In the special case that y and z are exactly the same size as x:
idx = find(ismembertol(x,xvalues));
corresponding_y = y(idx);
corresponding_z = z(idx);
In the case that they might not be the same size:
[row,col] = find(ismembertol(x,xvalues));
corresponding_y = y( sub2ind(size(y), row, col) );
corresponding_z = z( sub2ind(size(z), row, col) );

More Answers (0)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!