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?

Respuestas (1)

James Tursa
James Tursa el 27 de Abr. de 2017
Editada: James Tursa el 27 de Abr. de 2017
E.g., as a matrix of columns:
solutionV = zeros(___,numel(k)); % <-- fill this in to pre-allocate
:
solutionV(:,w) = solution(:,4);

2 comentarios

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

Iniciar sesión para comentar.

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 27 de Abr. de 2017

Comentada:

el 27 de Abr. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by