How to merge matrices generated from a for loop into one matrix.

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)

E.g., as a matrix of columns:
solutionV = zeros(___,numel(k)); % <-- fill this in to pre-allocate
:
solutionV(:,w) = solution(:,4);

2 Comments

That code generates a 3x59 matrix of zeros, with only the last column resembling the solutionV matrix. I'm looking to store the previous 58 matrices of solutionV in the same matrix.
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

Sign in to comment.

Categories

Tags

Asked:

on 27 Apr 2017

Commented:

on 27 Apr 2017

Community Treasure Hunt

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

Start Hunting!