I often see people try to store the results in a series of vectors with names like alpha1, alpha2, alpha3… This is not a good idea, it is hard to manipulate and refer to these variables. Better is to store each resultant vector as a row in a larger matrix.
By
Doug Hull
Doug first used MATLAB in 1994, could not figure it out until he got some help in 1995. He is now dedicated to making sure that no one else wastes a year of their life not knowing MATLAB like he did.
Hi Dough, another nice video tutorial.
The mat array should be preallocated first don’t you agree?
@Paulo
It depends. The point of my videos is to illustrate a concept clearly an concisely. Pre-allocation would be marginally better in a situation like this, but because the matrices are small it would be only a small improvement.
In real code, I would totally pre-allocate if this was a matrix of any real size, but for small ones I might or might not do it. I prefer clarity and brevity most of the time. If speed becomes an issue later, I can easily add that optimization.
Thanks for asking,
Doug