MATLAB: How to add loop vector iteration values to one big matrix

arrayfor loopMATLABmatricesmatrixmatrix arraymatrix manipulationSymbolic Math Toolbox

I have a loop that iterates a function 6 times, each time it produces a matrix. How do I add each iteration to a single matrix in a new column? I should see a 6×6 matrix at the end of the loop.
I would like X matrix to have all 6 rows answers. A single iteration of this function will provide an answer that will look similar to this:
2904.5 3019.3 3065.7 3070.6 3044.3 2996.1
The loop code:
for phi=0.5:0.2:1.5
X=Function(3000,1,phi)
end
The code above just replaces each iteration so I just see one line.
I tried to use something along the lines the code below, but it will not work, or will add everything to one row. (one other function would work if the answer is one variable, but will not work if there are multiple variables in one row)
it = it+1
X(it)=Function(3000,1,phi)
Thanks again!

Best Answer

Assuming that myfun outputs a 5-element vector, just use indexing like this:
phi = 0.5:0.2:1.5;
mat = nan(5,numel(phi));
for k = 1:numel(phi)
mat(:,k) = myfun(3000,1,phi(k));
end
This puts each result as one column of mat, which makes plotting easier. Or you could swap the dimensions of mat to put the results as rows. Whatever works for you.