Using ifelse in a loop - possible?
1 次查看(过去 30 天)
显示 更早的评论
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
采纳的回答
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 个评论
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 Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!