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 CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by