【发布时间】:2019-01-26 17:48:30
【问题描述】:
我有两个 4x1 矩阵。它们具有相同的元素,但矩阵中元素的行索引不同。
a = [200;100;100;300]
b = [100;100;200;300]
我需要在矩阵 a 中找到矩阵 b 的元素的索引号。 比如矩阵b的第三个元素是200,矩阵a中200的索引号是1。
结果应该是 = [2 3 1 4]
我写了这段代码,但它不起作用,因为有两个 100:
for i=1:4
c(1,i) = find(a(:,1) == b(i,1));
end
我有这个警告:Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
我应该怎么做才能拥有[2 3 1 4]?
【问题讨论】: