Using ifelse in a loop - possible?

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 comentario

Birdman
Birdman el 7 de Dic. de 2017
Of course possible, why not? What is your exact question?

Iniciar sesión para comentar.

 Respuesta aceptada

KL
KL el 7 de Dic. de 2017
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 comentarios

Jonas Maurer
Jonas Maurer el 7 de Dic. de 2017
Thanks very much KL. I´ll try this one...
KL
KL el 7 de Dic. de 2017
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,

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 7 de Dic. de 2017

Comentada:

KL
el 7 de Dic. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by