How to change matrix dimensions?

조회 수: 11 (최근 30일)
Rens
Rens 2012년 12월 6일
Hi,
I have a question regarding a 3D matrix with portfolio returns.
I have a 10000x35x12, which is 10000 simulated return paths for 35 years and 12 months in each year. Now I want to make this a 2D matrix with dimensions 10000x420 (35x12) such that the 420 months of return are in the right order. Can somebody help me with that?
Thanks in advance!
Greetz

답변 (4개)

Andrei Bobrov
Andrei Bobrov 2012년 12월 6일
M - your 3D array with size < 10000,35,12 >
out = reshape(permute(M, [1 3 2]),size(M,1),[]);

Muruganandham Subramanian
Muruganandham Subramanian 2012년 12월 6일
try this:
a=zeros(1000,35,12);
b=reshape(a,[1000 420]);

Azzi Abdelmalek
Azzi Abdelmalek 2012년 12월 6일
[n,m,p]=size(A)
b=reshape(A,n,p*m)
idx=reshape(1:p*m,m,p)'
out=b(:,idx(:))

Rens
Rens 2012년 12월 6일
Thanks guys! Appreciate it! All the different codes give the same return matrix so it should be alright!

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by