필터 지우기
필터 지우기

Creating structure using eval function

조회 수: 2 (최근 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 CenterFile Exchange에서 Whos에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by