- a(:,:,end+1) = randi(10,2,3); ~OR~
- a = cat(3,a,randi(10,2,3));
help in multi dimensional array 3D
조회 수: 5 (최근 30일)
이전 댓글 표시
hi I'm trying to increase the third dimension in a three-dimensional matrix can you help me? Example a=(2,3,5) after iteration it must be a=(2,3,7) thanks
댓글 수: 0
채택된 답변
Greg
2017년 1월 17일
편집: Greg
2017년 1월 17일
I assume that "a=(2,3,5)" means the corresponding length of each dimension of a is 2, 3 and 5.
Increasing variable size is rarely a good idea (there are plenty of articles on pre-allocation; I won't rehash).
a = zeros(2,3,7);
for ind3 = 1:7
a(:,:,ind3) = randi(10,2,3);
end
(But ALL of this trivial example can be done with "a = randi(10,2,3,7);")
If you really MUST dynamically allocate:
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!