Creating structure using eval function

6 visualizaciones (últimos 30 días)
Thulasi Durai Durai Samy
Thulasi Durai Durai Samy el 6 de Jul. de 2012
hello I need to create structure using eval function
required structure
laminate =
var1 = [0 0 0 0 0 0 0 0 0]
where
value = zeors(3);
evalin('base',['Laminate','=struct(''',''',var1,'''',''',value,''')'])
matlab error
Error using ==> horzcat CAT arguments dimensions are not consistent.
but for var1 = 'any string' is accepted
any idea to solve this problem.

Respuesta aceptada

Jan
Jan el 6 de Jul. de 2012
No, I'm really convinced that you do not need to create this using EVAL (or EVALIN as in your example). There is always a better solution than the evil EVAL. Do trust the FAQ and rely on hundrets or related threads in this forum, most of all consider that this method does produce problems for you already.
Therefore it is safer, simpler and more efficient to create the variable directly:
function Output = myFunc
Output.var1 = zeros(1, 6);
Now calling Laminate = myFunc from the command line create the wanted struct without dirty tricks.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by