필터 지우기
필터 지우기

Using ifelse in a loop - possible?

조회 수: 1 (최근 30일)
Jonas Maurer
Jonas Maurer 2017년 12월 7일
댓글: KL 2017년 12월 7일
Dear all,
is it possible to put "IFELSE" into a loop? I struggled. Mybe there is a trick?
happy for every answer! Tnaks a lot!
Jonas
  댓글 수: 1
Birdman
Birdman 2017년 12월 7일
Of course possible, why not? What is your exact question?

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

채택된 답변

KL
KL 2017년 12월 7일
You need to use indexing.
here is a small example. I'm gonna create a vector with 1s and 0s. In the for loop, I'll check if "an element" is either 1 or 2 and display a message.
dummy = [1 0 0 1 1 0 1 0 1 1 0 1];
for element_no = 1:numel(dummy)
if(dummy(element_no)==1)
disp('one')
else
disp('zero')
end
end
  댓글 수: 2
Jonas Maurer
Jonas Maurer 2017년 12월 7일
Thanks very much KL. I´ll try this one...
KL
KL 2017년 12월 7일
You're welcome. Please read the link I gave you and also the getting started exercises. They have examples for every question that you may have,

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

추가 답변 (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