Pre-locating an array
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi MATLAB guys,
I got stuck at some point and really appreciate your help.
Do you know how can I pre-locate the value of X in the following code? X is a matrix and for each i and j its dimentions will change. For example for given i and j, X has a dimention of Ri * Tj.
N = [1 2 3 4 5 6 7 8 9 10];
M = [11 22 33];
X === zeros %%%%pre-locating here
for k = 1 : 10
for m = 1 : N(k)
for i = 1 : 3;
for j = 1: M(i)
X(:,:, j,i,m,k) = sth;
end
end
end
end
Thanks in advance
댓글 수: 2
채택된 답변
James Tursa
2019년 4월 10일
편집: James Tursa
2019년 4월 10일
Numeric arrays must be rectangular. You cannot have different dimensions for different slices. To get that behavior you would need to use something like a cell array to store your different sized variables. E.g.,
X{j,i,m,k} = sth;
But, even though the contents of the cell array elements do not all have to be the same size, the cell array itself must be rectangular. You could still use it in your above scheme as long as it was OK to have a bunch of empty cells in the spots you were not using.
댓글 수: 3
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!