How to merge matrices generated from a for loop into one matrix.
Show older comments
k = 4:.05:6.90
ElementNum = numel(k)
results = zeros(3,numel(k))
for w = 1:numel(k)
A(1,1) = k(w)
solution = rref(A)
solutionV = solution(:,4)
end
The above code is what I have written. I am trying to merge all the solutionV matrices into one matrix. How do I do this?
Answers (1)
James Tursa
on 27 Apr 2017
Edited: James Tursa
on 27 Apr 2017
E.g., as a matrix of columns:
solutionV = zeros(___,numel(k)); % <-- fill this in to pre-allocate
:
solutionV(:,w) = solution(:,4);
2 Comments
patrick brannan
on 27 Apr 2017
James Tursa
on 27 Apr 2017
That last line was supposed to be obvious that it was inside the loop. E.g.,
k = 4:.05:6.90
ElementNum = numel(k)
results = zeros(3,numel(k))
solutionV = zeros(3,numel(k)); % <-- Pre-allocate
for w = 1:numel(k)
A(1,1) = k(w)
solution = rref(A)
solutionV(:,w) = solution(:,4); % <-- save as w'th column
end
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!