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 comentarios

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

Iniciar sesión para comentar.

 Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 12 de Jun. de 2013
Editada: Azzi Abdelmalek el 12 de Jun. de 2013

0 votos

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

Más respuestas (1)

Jan
Jan el 13 de Jun. de 2013
Editada: Jan el 13 de Jun. de 2013

0 votos

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

Categorías

Más información sobre Stress and Strain en Centro de ayuda y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by