Filter löschen
Filter löschen

Concatenate a 10x4x40 Double Matrix to 40x4

1 Ansicht (letzte 30 Tage)
Matthew
Matthew am 12 Apr. 2016
Bearbeitet: Roger Stafford am 13 Apr. 2016
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

Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 12 Apr. 2016
A=rand(10,4,40)
B=permute(A(1,:,:),[2 1 3])
out=B(:,:)'
  1 Kommentar
Roger Stafford
Roger Stafford am 13 Apr. 2016
Bearbeitet: Roger Stafford am 13 Apr. 2016
@Azzi: Don't you mean
B=squeeze(permute(A(1,:,:),[1,3,2]));

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Fangjun Jiang
Fangjun Jiang am 12 Apr. 2016
reshape(A(1,:,:),40,[])
  1 Kommentar
Roger Stafford
Roger Stafford am 13 Apr. 2016
@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,:,:)).';

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by