How to convert a sym array into a string array?

I have very long arrays of symbolic variables which I need to convert to cell arrays of strings: For example, turning this:
syms x y u
q = [x y u]
into this:
qs = {'x' 'y' 'u'}
something like num2string() but with syms? I'd appreciate any help, thanks.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 23 de Jul. de 2017
qc = arrayfun(@char, q, 'uniform', 0);

4 comentarios

quoroy
quoroy el 24 de Jul. de 2017
@Walter Roberson thank you so much! this worked perfectly, can't believe that was possible in one single line of code.
A slight variant of this is:
qc = arrayfun(@string, q);
which outputs a string array instead of a cell array filled with chars (consequently cellstr() can be used).
Chris J
Chris J el 2 de Jun. de 2021
Editada: Chris J el 2 de Jun. de 2021
then string1 = cell2mat(qc)
syms x y u
q = [x y u]
q = 
cellstr(string(q))
ans = 1×3 cell array
{'x'} {'y'} {'u'}

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Preguntada:

el 23 de Jul. de 2017

Comentada:

el 2 de Jun. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by