How to store output of a for loop in a matrix?

3 views (last 30 days)
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]
for index = 1:3

Accepted Answer

madhan ravi
madhan ravi on 18 Feb 2019
Idir=zeros(size(P)); % this is how you preallocate before loop
Note: In this case you don’t need a loop.
madhan ravi
madhan ravi on 18 Feb 2019
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 ?

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by