How to store output of a for loop in a matrix?
1 次查看(过去 30 天)
显示 更早的评论
Hi guys,
I'm having difficulty storing my output values from a loop into a matrix. And whenever I try the solution mentioned in other examples the error preallocate comes up.
My code is below:
P= [10 20 30]
A=1230
B=0.14
Idir=0
for index = 1:3
Idir=(A/(exp(B/sin(P(index)))))
end
0 个评论
采纳的回答
madhan ravi
2019-2-18
Idir=zeros(size(P)); % this is how you preallocate before loop
Note: In this case you don’t need a loop.
5 个评论
madhan ravi
2019-2-18
Definitely I would suggest you to read the link suggested by stephen , once if you get familiarized with all the functions then you will know
When to use it ?
How to use it ?
Where to use it ?
更多回答(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!