MATLAB: Extracting the values using [row,col]

columnextractionMATLABrow

I have successfully found the row and col's in "x" , (a 61×61 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

Best Answer

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) );