convert a 3D matrix to a 2D matrix

조회 수: 2 (최근 30일)
Ara Jo
Ara Jo 2020년 9월 23일
댓글: madhan ravi 2020년 9월 23일
Hello,
I'm trying to convert a A by B by C matrix (3D) into a A*C by B matrix (2D). But I need the column (with A*C elements) to be not stacked, but alternated. To explain,
I would like to convert a 2 by 2 by 3 matrix X:
val(:,:,1) =
1 2
1 2
val(:,:,2) =
2 3
2 3
val(:,:,3) =
3 4
3 4
into 2*3 by 2 matrix:
[1 2
2 3
3 4
1 2
2 3
3 4]
I have tried:
X1=permute(X,[1 3 2]);
X2=reshape(X1,[6,2]);
but it generates:
X2 =
1 2
1 2
2 3
2 3
3 4
3 4
which is NOT what I want.
Is there a way to do this? Any advice appreciated!

채택된 답변

madhan ravi
madhan ravi 2020년 9월 23일
reshape(permute(val, [2, 1, 3]), size(val, 2), []).'
  댓글 수: 2
Ara Jo
Ara Jo 2020년 9월 23일
But this generates X2, which is not what I'm trying to get?
madhan ravi
madhan ravi 2020년 9월 23일
X2 = reshape(permute(val, [3, 1, 2]), [], size(val, 2))

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

추가 답변 (1개)

KSSV
KSSV 2020년 9월 23일
iwant = X2 ;
iwant(1:2:end,:) = X2(1:3,:) ;
iwant(2:2:end,:) = X2(4:end,:) ;

카테고리

Help CenterFile Exchange에서 Pulse width modulation (PWM)에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by