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 Kommentare

Jan
Jan am 13 Jun. 2013
Do you mean:
cycles = {[0 20], [-160 150], [-40 330], [-40 170], [-20 180]}
?
Mohammed
Mohammed am 17 Jun. 2013
yes

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 12 Jun. 2013
Bearbeitet: Azzi Abdelmalek am 12 Jun. 2013

0 Stimmen

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

Weitere Antworten (1)

Jan
Jan am 13 Jun. 2013
Bearbeitet: Jan am 13 Jun. 2013

0 Stimmen

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

Kategorien

Mehr zu Stress and Strain finden Sie in Hilfe-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