要检索原始索引,您必须将两个条件的索引的内存保留在x和y上(我将其放入数组cX和cY中),然后使用函数
ind2sub.
NB: your code is a little bit confusing since x stands for the lines
and y for the columns, but I have kept the same convention in my
answer.
在实践中,这给出了:
% --- 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
最好,