A simple for loop question
3 次查看(过去 30 天)
显示 更早的评论
isb=6;
for i=1:3
nta=(1+isb).^2/isb
isb=nta;
end
Hello everyone. I have just started to use MATLAB and I wrote the code above. My question is: When I ran this code, MATLAB gave me only last value of nta. But I need all nta values as an matrix. How can I write it? Thanks.
采纳的回答
Mazdack Ameri
2021-5-9
编辑:Mazdack Ameri
2021-5-9
you could do something like this:
isb=6;
nta_matrix = zeros(3,1); %initializing, it usually saves memory.
for i=1:3
nta_matrix(i) = (1+isb).^2/isb;
isb=nta_matrix(i);
end
更多回答(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!