use of eval
古いコメントを表示
I am trying to use evalfunction but are having a hard time:
>> plots=[3 4 6 1]
plots =
3 4 6 1
>> whatplot=input('type type of graph: ','s')
type type of graph: bar
whatplot =
bar
>> eval(whatplot(plots))
??? Index exceeds matrix dimensions.
>>
why wont it evaluate it to a graph with bars?
採用された回答
その他の回答 (2 件)
Patrick Kalita
2011 年 10 月 21 日
I think feval would be a better option here. It is a safer than eval, and it easily accommodates passing input arguments:
feval( whatplot, plots )
3 件のコメント
Fangjun Jiang
2011 年 10 月 21 日
Yes. feval() is the way to go. I was thinking about inline(), @, etc.
Jan
2011 年 10 月 21 日
@Tor: Avoid EVAL. As you see, it causes troubles.
Tor Fredrik Hove
2011 年 10 月 21 日
Wayne King
2011 年 10 月 21 日
plots=[3 4 6 1];
whatplot = 'bar';
eval([whatplot '(plots)'])
1 件のコメント
Wayne King
2011 年 10 月 21 日
also, see the comments by other posters above.
カテゴリ
ヘルプ センター および File Exchange で 2-D and 3-D Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!