if-else if inside the for loop
2 次查看(过去 30 天)
显示 更早的评论
The numbers 1 to 24 is stored inside the array i
i =[ 1 ..24]
Here, lets say for i = 1,2,4,5,6 and 13,14,16,17,18 I have to define a = 3 and rest of the numbers I have to define a = 4. How to implement this using if else inside the for loop.
for
if (i = 1,2,4,5,6,13,14,16,17,18)
a=3;
else
a=4
end
end
2 个评论
采纳的回答
Sulaymon Eshkabilov
2023-2-18
Here is how to do it in for .. end loop
N = 1:24;
for ii=1:length(N);
if ismember(ii, [1,2,4,5,6,13,14,16,17,18])
a(ii)=3;
else
a(ii)=4;
end
end
a
0 个评论
更多回答(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!