converting an array of n symbolic variables to a cell array with n elements

1 Ansicht (letzte 30 Tage)
Hi
Could somebody tell me a way to convert the symbolic array [ x, y , z ] to the 3 element cell array Cell, where Cell{1} = x, Cell{2} = y, etc? You would think it should be possible to do this with mat2cell, but this converts [ x, y, z ] to the a single element cell variable, i.e., Y = cell2mat([x,y,z]) returns T{1} = [ x,y,z].
Thanks!

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 12 Jan. 2013
num2cell() rather than mat2cell()

Weitere Antworten (1)

Azzi Abdelmalek
Azzi Abdelmalek am 12 Jan. 2013
Bearbeitet: Azzi Abdelmalek am 12 Jan. 2013
syms x y z
a=[x y z]
for k=1:numel(a)
A{k}=a(k)
end
  2 Kommentare
Leo Simon
Leo Simon am 12 Jan. 2013
Thanks Azzi, was trying to do it without a loop, I hate loops on principle
José-Luis
José-Luis am 12 Jan. 2013
Loops are not always evil. They can make for clearer code and are sometimes faster than the vectorized alternative.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Data Type Conversion finden Sie in Help 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