Build matrix of different size column vectors generated inside a for loop
16 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Paul Broadley
el 27 de En. de 2021
Comentada: Paul Broadley
el 1 de Feb. de 2021
Hi,
Inside a for loop, I am generating column vectors of different lengths that are being plotted against time for a number of datasets.
How do I take these different sized column vectors and store them in a matrix/ table/ array, such that the number of rows is equal to the longest column vector, and the number of columns is equal to the number of iterations in the for loop?
Where I have got up to:
for u = 1:length(listings)
ForceNext(u) = ForceTrunc(u);
ForceAll = zeros(75, 1);
ForceAll{:,u} = [ForceAll, ForceNext(u)]
end
I have also attached the full script, with lines 127 - 156 relating to the question. I will later take mean values of each row of the matrix I wish to create, and plotting the subsequent vector against a time series.
Thanks for any and all help
3 comentarios
Bob Thompson
el 27 de En. de 2021
Is the size captured in one of your other dataset variables? If the size is captured somewhere else you can use that value to more organically specify the size of the array.
Respuesta aceptada
Stephen23
el 27 de En. de 2021
Editada: Stephen23
el 27 de En. de 2021
Inside the loop store the vectors in a preallocated cell array. Then after the loop use PADCAT (download required):
To get you started (pseudocode):
N = number of iterations
C = cell(1,N);
for k = 1:N
... your code
C{k} = output vector
end
M = padcat(C{:});
Más respuestas (0)
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!