Making matrices of different dimensions and clubbing them together

조회 수: 3 (최근 30일)
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.

채택된 답변

Stephen23
Stephen23 2020년 3월 6일
편집: Stephen23 2020년 3월 6일
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
shahzer rahman
shahzer rahman 2020년 3월 7일
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 2020년 3월 7일
P = [cellfun(@(v)1:numel(v),C,'uni',0); C];
plot(P{:})

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Mario Malic
Mario Malic 2020년 3월 6일
You can use
A (i, 1:length(output_matrix)) = your data

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by