Extract 2 rows each to be stored in column.

1 回表示 (過去 30 日間)
Siti Suhaila
Siti Suhaila 2017 年 8 月 5 日
コメント済み: Star Strider 2017 年 8 月 5 日
A = [7
9
2
1
8
3];
for i=1:6
B{i}=A(1:2,:);
end
Hello everyone, I have some difficulty related with extract 'n' rows to be stored in the column. I need the rows to be like below, however, I got the result as B=[7;9] instead.
B{1}= [7
9]
B{2}= [2
1]
B{3}= [8
3]

採用された回答

KSSV
KSSV 2017 年 8 月 5 日
Why you want a loop? You can do this in one step using reshape.
B=reshape(A,2,[]);
  1 件のコメント
Siti Suhaila
Siti Suhaila 2017 年 8 月 5 日
Thank you very much......appreciated it...

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

その他の回答 (1 件)

Star Strider
Star Strider 2017 年 8 月 5 日
Try this:
R = reshape(A, 2, []);
B = mat2cell(R, 2, ones(1,size(R,2)));
Check = [B{:}] % Check Result
Check =
7 2 8
9 1 3
  2 件のコメント
Siti Suhaila
Siti Suhaila 2017 年 8 月 5 日
Thank you very much......appreciated it...
Star Strider
Star Strider 2017 年 8 月 5 日
My pleasure.
Note that my code gives you the cell array your Question wants.

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by