numeric array to cell array

1 vue (au cours des 30 derniers jours)
Mohammed
Mohammed le 12 Juin 2013
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 commentaires
Jan
Jan le 13 Juin 2013
Do you mean:
cycles = {[0 20], [-160 150], [-40 330], [-40 170], [-20 180]}
?
Mohammed
Mohammed le 17 Juin 2013
yes

Connectez-vous pour commenter.

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 12 Juin 2013
Modifié(e) : Azzi Abdelmalek le 12 Juin 2013
cycles=reshape(stress,2,[])
%you can also create cell array
out=arrayfun(@(x) cycles(:,x),1:size(cycles,2),'un',0)
  1 commentaire
Mohammed
Mohammed le 17 Juin 2013
Thanks

Connectez-vous pour commenter.

Plus de réponses (1)

Jan
Jan le 13 Juin 2013
Modifié(e) : Jan le 13 Juin 2013
stress = [0 20 -160 150 -40 330 -40 170 -20 180];
C = num2cell(reshape(stress, 2, []).', 2);
  1 commentaire
Mohammed
Mohammed le 17 Juin 2013
Thanks

Connectez-vous pour commenter.

Catégories

En savoir plus sur Stress and Strain dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by