MATLAB Answers

Leo Simon

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

Asked by Leo Simon
on 12 Jan 2013


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].




No products are associated with this question.

2 Answers

Answer by Walter Roberson
on 12 Jan 2013
 Accepted answer

num2cell() rather than mat2cell()

  1 Comment

Thanks, can't believe I didn't try this.

Answer by Azzi Abdelmalek
on 12 Jan 2013
Edited by Azzi Abdelmalek
on 12 Jan 2013
syms x y z
a=[x y z]
for k=1:numel(a)


Thanks Azzi, was trying to do it without a loop, I hate loops on principle

on 12 Jan 2013

Loops are not always evil. They can make for clearer code and are sometimes faster than the vectorized alternative.

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!