MATLAB Answers

Skipping the for loop if condition is meet

조회 수: 2(최근 30일)
Prakhar Modi
Prakhar Modi 20 Aug 2019
편집: Rik 20 Aug 2019
Hello everyone,
for example,
a = 1, 2, 3,4,5
b=7,8,3,9,6
so i write code
for i=1:5
c(i)=a(i)-b(i)
if (a(i)==b(i))
% if this condition is satisfied i.e. as a(3)=b(3)
% so i want that c(3) should be skipped and then c(4) should be calculated
continue
end
end
So what should i write in place of % so that it will skip the c(3) iteration and continue to further calculation.

  댓글 수: 1

Rik
Rik 20 Aug 2019
Your code already seems to do that. What is your question? For this specific example, Torsten's code would work better.

로그인 to comment.

답변(1개)

Torsten
Torsten 20 Aug 2019
idx = a~=b;
c(idx) = a(idx)-b(idx);

  댓글 수: 0

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.

제품


릴리스

R2018a

Translated by