Reshape 1D to 3D array
    조회 수: 14 (최근 30일)
  
       이전 댓글 표시
    
I have a 1D array (365x1) that I need to reshape into a 3D array (365x1x1) to divide into 3D array (365x721x1440). What's the most efficient means of accomplishing this task?
채택된 답변
  the cyclist
      
      
 2023년 8월 5일
        MATLAB arrays implicitly have length-1 dimensions after the defined dimensions. For example
% Define 365x1 array
M = rand(365,1);
% Length in 3rd dimension
size(M,3)
% Length in 31st dimension
size(M,31)
Regarding how that ends up being (365x721x1440), you'll need to provide more detail.
댓글 수: 4
  DGM
      
      
 2023년 8월 6일
				
      편집: DGM
      
      
 2023년 8월 6일
  
			I think we're getting confused by the suggestion of "reshaping".  The way it appears to me, reshaping A is not necessary.  It appears as this is simply a misunderstanding how to make array sizes compatible for arithmetic operations.  Consider the example:
A = (1:4).' % a column vector
B = 2*ones(4,4,2) % a 3D array with the same page height
% you could expand A to have the same size as B
% A = repmat(A,[1 4 2]);
% but it's not necessary
A./B
So long as the arrays are compatibly-sized along their non-singleton dimensions, you should be able to perform elementwise arithmetic without explicitly expansion.  If you were running a version older than R2016b, the recommended method would be to use bsxfun() instead of repmat().
Of course, I might be interpreting the question wrong.
추가 답변 (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!



