矩阵检索或索引matlab,求矩阵元素匹配条件的索引 – Matlab

要检索原始索引,您必须将两个条件的索引的内存保留在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

最好,

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值