Comparing values within two vectors

Hello everyone, I have two vectors of different length and I need to iterate through the first one A = randi(25,372,1) and find the corresponding value in vector B = 1:1:25 and return it's index. I need to do this for every single value in vector A (372) What I have so far:
A = randi(25,372,1)';
B = (1:1:25)';
for i = 1:1:372
ValueA = A(i);
for j = 1:1:25
ValueB = (Bj);
if B(j) == A(i)
[index, Lib] = intersect(B,A);
end
end
end
Any help will be much appreciated

回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 11 月 14 日

1 投票

A = randi(25,372,1);
B=1:25;
[ ~,jj]=ismember(A,B)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

製品

質問済み:

2014 年 11 月 14 日

回答済み:

2014 年 11 月 14 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by