use of eval
조회 수: 4 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
채택된 답변
Wayne King
2011년 10월 21일
Your call to input() returns the string bar in whatplot
but whatplot(plots) is not a string.
eval([whatplot '(plots)'])
댓글 수: 4
추가 답변 (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
참고 항목
카테고리
Help Center 및 File Exchange에서 Discrete Data Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!