How to reshape a matrix in a specific way?

4 ビュー (過去 30 日間)
Ciaran Green
Ciaran Green 2018 年 2 月 8 日
コメント済み: Ciaran Green 2018 年 2 月 8 日
If I have a matrix (A) that is 10x4, how would I reshape this matrix to be a new 5x8 matrix (B) so that the first two rows of A are concatenated to be the first row of B, the 3rd and 4th row of A were the second row of B etc.
Thanks in advance for your help

採用された回答

Stephen23
Stephen23 2018 年 2 月 8 日
編集済み: Stephen23 2018 年 2 月 8 日
Just use reshape and transpose (where 8 is the required number of columns):
>> A = rand(10,4); % fake data
>> B = reshape(A.',8,[]).';
and checking:
>> A(1:2,:)
ans =
0.42279 0.17374 0.11111 0.86420
0.25314 0.46765 0.14823 0.10467
>> B(1,:)
ans =
0.42279 0.17374 0.11111 0.86420 0.25314 0.46765 0.14823 0.10467
In your case use (where 25536*72 is the required number of columns):
B = reshape(A.',25536*72,[]).';
  1 件のコメント
Ciaran Green
Ciaran Green 2018 年 2 月 8 日
Fantastic, makes perfect sense - thank you for your help.

サインインしてコメントする。

その他の回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2018 年 2 月 8 日
編集済み: Fangjun Jiang 2018 年 2 月 8 日
A=reshape(1:40,10,4);
B=[A(1:2:10,:) A(2:2:10,:)]
  3 件のコメント
Stephen23
Stephen23 2018 年 2 月 8 日
編集済み: Stephen23 2018 年 2 月 8 日
Fangjun Jiang used the first line to define some fake data: it defines a matrix A with size 10x4, just like you specified in your question but did not provide us with. There is nothing special about this matrix (it contains the values 1 to 40), and you certainly don't need this in your code as you apparently already have matrix A.
Ciaran Green
Ciaran Green 2018 年 2 月 8 日
Oh, oops, makes sense - thank you for clarification.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by