필터 지우기
필터 지우기

Concatenate a 10x4x40 Double Matrix to 40x4

조회 수: 1 (최근 30일)
Matthew
Matthew 2016년 4월 12일
편집: Roger Stafford 2016년 4월 13일
Hello,
I have a matrix A() that is 10x4x40. I would only like the first row of the matrix A(1,:,:) but want to vertically concatenate the data so it transforms into B() that is 40x4. How would I do this?
Right now I have tried doing
vertcat(A(:,:))
which returns a concatenated matrix of 1x160. Do I need to use a loop to do this? Please help!
Thank you

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2016년 4월 12일
A=rand(10,4,40)
B=permute(A(1,:,:),[2 1 3])
out=B(:,:)'
  댓글 수: 1
Roger Stafford
Roger Stafford 2016년 4월 13일
편집: Roger Stafford 2016년 4월 13일
@Azzi: Don't you mean
B=squeeze(permute(A(1,:,:),[1,3,2]));

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

추가 답변 (1개)

Fangjun Jiang
Fangjun Jiang 2016년 4월 12일
reshape(A(1,:,:),40,[])
  댓글 수: 1
Roger Stafford
Roger Stafford 2016년 4월 13일
@Fangjun: When Matthew states that a 40 x 4 array is to be produced, I believe it implicit in this statement is the assumption that what were 40-element sequences along the 3rd dimension for a given row and column index are to be preserved in the columns of the resulting 40 x 4 array. However 'reshape' will not accomplish this. To take a simpler case suppose
A = [1 2 3 4 5 6;
7 8 9 10 11 12];
We would like a 6 x 2 array B to be:
B = [1 7;
2 8;
3 9;
4 10;
5 11;
6 12]
where the former rows become the columns. However B = reshape(A,6,2) will give:
B = [1 4;
7 10;
2 5;
8 11;
3 6;
9 12]
In other words 'reshape' would break up the sequences 1,2,3,4,5,6 and 7,8,9,10,11,12. I don't think Matthew would like that as applied to the 40-element columns of the result.
However, this would work:
B = squeeze(A(1,:,:)).';

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

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by