How to create a 3D array with matrices of unequal dimentions

조회 수: 6 (최근 30일)
Benjamin Schuessler
Benjamin Schuessler 2018년 1월 8일
댓글: Benjamin Schuessler 2018년 1월 8일
Hi all!
I'm a little stuck here, I have a loop:
for i = 1:length(n)
(extras)
n_input = n(i)
tjdf = tjdfCoef(q12,q23,n_input,lambda,mu
end
where the output tjdf is a matrix that has a larger and larger size after each iteration. Is there anyway to put all outputs into a 3D matrix, even though all outputs aren't equal dimension?
Thanks,
Ben

채택된 답변

Jan
Jan 2018년 1월 8일
편집: Jan 2018년 1월 8일
No, a 3D array must have the same number of rows and columns for all pages. Use a cell array instead:
tjdf = cell(1, length(n));
for i = 1:length(n)
(extras)
n_input = n(i)
tjdf{i} = tjdfCoef(q12,q23,n_input,lambda,mu)
end
Cell arrays are useful, if it is meaningful to access the elements by indices and if the elements have different sizes and/or types.
  댓글 수: 1
Benjamin Schuessler
Benjamin Schuessler 2018년 1월 8일
JAN! This worked amazingly... I didn't even think of using cells. Much appreciated!
Cheers.

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

추가 답변 (0개)

카테고리

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