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!