Is there a more efficient way to compute this other than using a loop ?

1 回表示 (過去 30 日間)
Rayan Glus
Rayan Glus 2021 年 5 月 31 日
コメント済み: Rayan Glus 2021 年 5 月 31 日
Hello,
Say, vectors a and b have different sizes. I wonder if there is a simpler and more efficient way of writing the lines below.
b = [1 3 4 7 8 10 2 5 6];
a = [2 3 9];
for ii = 1:length(a)
b(b==a(ii))=[];
end
Output:
b = 1 4 7 8 10 5 6
Thanks!

採用された回答

Matt J
Matt J 2021 年 5 月 31 日
編集済み: Matt J 2021 年 5 月 31 日
b=setdiff(b,a,'stable')

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by