0
votes

in Matlab I have a (436 x 377) matrix, called 'distance_center', which contains (Euclidean) distances with respect to the center. The center is in the position (243,57) = (i,j), which I have chosen as the origin. So on position (243,57) of the matrix 'distance center' I have the value 0. For all the other elements in the matrix I have calculated the distance from the center with sqrt((x_i - x_j)^2 + (y_i - y_j)^2).

I now want to write a program in Matlab that does the following from me:

I want to know the positions (indices (i,j)) of all the elements that satisfy a certain condition. For example: I want to know the positions of the points whose Euclidean distance d from the center satisfy 390 < d < 400. I also want Matlab to tell me how many elements satisfy this condition.

I was thinking of using the command 'discretize', but I'm not sure how to use it.

Any help on how to do this is appreciated.

1

1 Answers

1
votes

If efficiency is not of importance, I'd suggest to use find, for example

 I = find(distance_center< 400 & distance_center >390 );

That way, I represents the coordinates in the matrix distance_center that you are interested in, which is dominant in the row coordinate. You can get the original coordinates with ind2sub. In your case: [i,j]=ind2sub(size(distance_center),I); The total number of elements that satisfy your requirements are equal to length(I)