Can this be vectorized?
古いコメントを表示
Dear all,
I have two vectors A and B of respective sizes na and nb, with na>=nb. All elements in B are unique while the elements in A are not. But all elements in A are in B. I would like to create a mapping between A and B and one way to do that is as follows:
A=nan(na,1);
for ii=1:nb
A(A==B(ii))=ii;
end
This works well be becomes prohibitively expensive for large na. And so my question is whether there is a way of getting rid of the for loop and/or creating this mapping differently.
Thanks,
P.
1 件のコメント
Andrei Bobrov
2014 年 10 月 30 日
can so:
out = nan(na,1);
for ii=1:nb
out(A==B(ii))=ii;
end
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で NaNs についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!