How to create three columns for matrix after indexing
    조회 수: 8 (최근 30일)
  
       이전 댓글 표시
    
Dear all, I have a 8X8X8 three dimensional matrix. I would like to create 512X4 matrix so that first column give the position of x, second column the position of y and third one for z position.
I have a code like this
nx = size(dyzw,1);
ny = size(dyzw,2);
nz = size(dyzw,1);
N = nx*ny*nz;
bigData = dyzw(:);
bigMatrix = zeros(N, 4);
for i = 1: N
    bigMatrix(i,4) = bigData(i);
    for j = 1: nx
        for k = 1: ny
            for l = 1:nz
                bigMatrix(i,1) =j;
                bigMatrix(i,2) =k;
                bigMatrix(i,3) =l;
            end 
        end
    end
end
But I failed to produce the matrix as I want. Could you please check my code please.
Thanks
댓글 수: 0
채택된 답변
  Jos
      
 2015년 2월 18일
        
      편집: Jos
      
 2015년 2월 18일
  
      Hi Mahesh,
this will do what you want
nx = size(dyzw,1);
ny = size(dyzw,2);
nz = size(dyzw,3);
N = nx*ny*nz;
bigMatrix = zeros(N,4);
i = 0;
for j = 1:nx
    for k = 1:ny
        for l = 1:nz
            i = i+1;
            bigMatrix(i,1) = j;
            bigMatrix(i,2) = k;
            bigMatrix(i,3) = l;
            bigMatrix(i,4) = dyzw(j,k,l);
        end 
    end
end
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
				Help Center 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
			
	제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

