How to create a variable from cell array contents?

5 visualizaciones (últimos 30 días)
Akbar
Akbar el 7 de Jun. de 2018
Respondida: Nikolai Jakuba el 18 de Jun. de 2018
I have a cell Array vector as attached (length may vary). It contains variable names.
mycell =
5×1 cell array
{'x' }
{'y' }
{'var1'}
{'var2'}
{'var3'}
How to create a new variable as follows?
out = [x;y;var1;var2;var3];
  2 comentarios
Stephen23
Stephen23 el 7 de Jun. de 2018
Editada: Stephen23 el 7 de Jun. de 2018
This approach will force you into writing slow, complex, buggy code. Read this to know why:
Rather than accessing variable names in the workspace, you should revise your concept and use simpler, more efficient, and more robust methods, e.g. indexing, structure+fieldnames, table+variables, etc.
Akbar
Akbar el 8 de Jun. de 2018
Editada: Akbar el 8 de Jun. de 2018
Thank you for advice Stephen. I think I will go with tables then.

Iniciar sesión para comentar.

Respuesta aceptada

Nikolai Jakuba
Nikolai Jakuba el 18 de Jun. de 2018
You can use struct:
for idx_cell = 1:size(mycell,1) out.(mycell{idx_cell})={}; end

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by