How can I convert while loop to for loop?
2 次查看(过去 30 天)
显示 更早的评论
This is the loop
while i<=5
E_(i)= x(i).^2;
if i==1
disp(['The amount of energy at fundamental harmonic is: ' num2str(E_(i))]);
else
disp(['The amount of energy at harmonic ' num2str(i-1) ' is: ' num2str(E_(i))]);
end
i=i+1;
end
0 个评论
采纳的回答
Voss
2022-1-5
Assuming the while loop starts with i = 1:
for i = 1:5
E_(i)= x(i).^2;
if i==1
disp(['The amount of energy at fundamental harmonic is: ' num2str(E_(i))]);
else
disp(['The amount of energy at harmonic ' num2str(i-1) ' is: ' num2str(E_(i))]);
end
end
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!