我有:
A=[3 4 5 6 7;1 0 3 5 9;1 8 10 11 12];
B=[1 0 5 5 9 ];
我想在A中找到B,但是像这样:
我应该在最后C=[2 2 1 2 2]
for i = 1:length(B)
index(i) = find(A(:,i) == B(i),1)
end
error: Improper assignment with rectangular empty matrix.
答案 0 :(得分:0)
您的代码几乎正确无误。您必须初始化index
- 变量:
index = zeros(1,size(A,2));
for i = 1:length(B)
index(i) = find(A(:,i) == B(i),1);
end
index
index =
2 2 1 2 2