フィルターのクリア

split a n*m-by-1 vector into n m-by-1 vectors

3 ビュー (過去 30 日間)
jimaras
jimaras 2014 年 3 月 14 日
コメント済み: Star Strider 2014 年 3 月 14 日
I would like to split a m*n-by-1 vector into smaller ones, e.g. m-by-1. I have tried to think of an efficient way but i have not.
Any ideas?
Thank you.

採用された回答

Star Strider
Star Strider 2014 年 3 月 14 日
I suggest reshape:
A=[1; 2; 3; 4; 5; 6; 7; 8];
B = reshape(A,2,4)
The columns of B are your 2x1 vectors:
B =
1.0000e+000 3.0000e+000 5.0000e+000 7.0000e+000
2.0000e+000 4.0000e+000 6.0000e+000 8.0000e+000
  2 件のコメント
jimaras
jimaras 2014 年 3 月 14 日
Exactly what I wanted. Thank you!
Star Strider
Star Strider 2014 年 3 月 14 日
My pleasure!

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

その他の回答 (2 件)

Benjamin Avants
Benjamin Avants 2014 年 3 月 14 日
I think the easiest method uses num2cell:
myArray = ones(3,4,1);
myCell = num2cell(myArray,1)
ans =
[3x1 double] [3x1 double] [3x1 double] [3x1 double]
You then have a 4 element cell array of 3x1 numerical arrays. Not sure if that's what you're looking for, but perhaps its a step in the right direction. The second parameter of num2cell determines which dimension is split into cells. Making that argument a 2 would yield a 3 element cell array of 4x1 numerical arrays.
  1 件のコメント
jimaras
jimaras 2014 年 3 月 14 日
Basically, no. Maybe I didn't post the question correctly. I have the following vector:
A=[1; 2; 3; 4; 5; 6; 7; 8]
and I want to split it into 4 smaller ones (2x1) how can I do this.
P.s. Number are chosen randomly.

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


Joseph Cheng
Joseph Cheng 2014 年 3 月 14 日
How about putting it into the 3rd dimension? A=reshape(A,2,1,4) then you can reference A(:,:,1) to A(:,:,4) will be the smaller ones?

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by