Making matrices of different dimensions and clubbing them together

8 visualizaciones (últimos 30 días)
I am running a for loop which gives row matrices as the output.
for (i=1), output matrix is a [1*1114] matrix.
for (i=2), output matrix is a [1*1213] matrix
the dimensions of the matrices keep increasing.
my desired final matrix is a matrix that contains all the stored values of all iterations.
Please help.
Error says : Unable to perform assignment because the size of the left side is 1-by-1114 and the size of the right side is 1-by-1213.
I am new to matlab.

Respuesta aceptada

Stephen23
Stephen23 el 6 de Mzo. de 2020
Editada: Stephen23 el 6 de Mzo. de 2020
A simple and efficient approach using a cell array:
N = number of loop iterations
C = cell(1,N);
for k = 1:N
... your code
C{k} = [...] % output vector
end
V = [C{:}] % output vectors concatenated into one
See:
  5 comentarios
shahzer rahman
shahzer rahman el 7 de Mzo. de 2020
Hey Stephen. Need some more help, man. I am trying to plot each cell values. How do I do that?
Rememeber each cell has a row matrix.
Stephen23
Stephen23 el 7 de Mzo. de 2020
P = [cellfun(@(v)1:numel(v),C,'uni',0); C];
plot(P{:})

Iniciar sesión para comentar.

Más respuestas (1)

Mario Malic
Mario Malic el 6 de Mzo. de 2020
You can use
A (i, 1:length(output_matrix)) = your data

Categorías

Más información sobre Matrix Indexing 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!

Translated by