Creating structure using eval function

6 ビュー (過去 30 日間)
Thulasi Durai Durai Samy
Thulasi Durai Durai Samy 2012 年 7 月 6 日
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.

採用された回答

Jan
Jan 2012 年 7 月 6 日
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.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeWhos についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by