Matrix Index Matrix Alignment State Index Search

Given a matrix Z (i, j) such that it maps two arrays X (i) and Y (j). I am trying to find the elements of Z (and therefore the corresponding X and Y) in a specific range.

Now I am doing the following using logical indexing. Given this example

 X = 1:5;
 Y = 1:5;
 Z =    [17    24     1     8    15
         23     5     6    14    16
          4     6    13    20    22
         10    12    19    21     3
         11    18    25     2     9]
 Z((X>1 & X<4),Y==3)

This works fine, but now I want to find the minimum return values ​​from this particular range,

What am i doing with

min(Z((X>1 & X<4),Y==3))

But now, how do I return the corresponding X and Y minimum values? Since my boolean indexing returns an array, all the methods I've tried so far return the min index in the response array, not the original Z-matrix.

I can not use

[row col] = find(Z==min(Z((X>1 & X<4),Y==3)))

Due to repetitions. What are my alternatives?

+4
2

, x y ( cX cY), ind2sub.

NB: , x y , .

:

% --- Definition
X = 1:5;
Y = 1:5;
Z =    [17    24     1     8    15
        23     5     6    14    16
         4     6    13    20    22
        10    12    19    21     3
        11    18    25     2     9];

% --- Get the values of interest
cX = find(X>1 & X<4);
cY = find(Y==3);
v = Z(cX,cY);

% --- Get position of the minimum in the initial array
[~, I] = min(v(:));
[Ix, Iy] = ind2sub([numel(cX) numel(cY)], I);

i = cX(Ix);      % i = 2
j = cY(Iy);      % j = 3

,

+5

-

%// Calculate all indices of the grid created with those two X-Y conditions
idx = bsxfun(@plus,(find(Y==3)-1)*size(Z,1),find((X>1 & X<4)).') %//'

%// Get the index corresponding to minimum from that grided Z
[~,min_idx] = min(Z(idx(:)))

%// Get corresponding X-Y indices by using indices calculated earlier
[indX,indY] = ind2sub([numel(X) numel(Y)],idx(min_idx))
+4

All Articles