numeric array to cell array

Hi
I want to convert the following numeric array to cell array of cells having two elements each. Any help?
stress = [0 20 -160 150 -40 330 -40 170 -20 180]
what is required is:
cycles = [[0 20] [-160 150] [-40 330] [-40 170] [-20 180]]

2 件のコメント

Jan
Jan 2013 年 6 月 13 日
Do you mean:
cycles = {[0 20], [-160 150], [-40 330], [-40 170], [-20 180]}
?
Mohammed
Mohammed 2013 年 6 月 17 日
yes

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

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 6 月 12 日
編集済み: Azzi Abdelmalek 2013 年 6 月 12 日

0 投票

cycles=reshape(stress,2,[])
%you can also create cell array
out=arrayfun(@(x) cycles(:,x),1:size(cycles,2),'un',0)

その他の回答 (1 件)

Jan
Jan 2013 年 6 月 13 日
編集済み: Jan 2013 年 6 月 13 日

0 投票

stress = [0 20 -160 150 -40 330 -40 170 -20 180];
C = num2cell(reshape(stress, 2, []).', 2);

カテゴリ

ヘルプ センター および File ExchangeCell Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by