Skipping the for loop if condition is meet

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 2019년 8월 20일
Your code already seems to do that. What is your question? For this specific example, Torsten's code would work better.

댓글을 달려면 로그인하십시오.

답변 (1개)

Torsten
Torsten 2019년 8월 20일

0 개 추천

idx = a~=b;
c(idx) = a(idx)-b(idx);

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

릴리스

R2018a

질문:

2019년 8월 20일

편집:

Rik
2019년 8월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by