use of eval
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Wayne King
il 21 Ott 2011
Your call to input() returns the string bar in whatplot
but whatplot(plots) is not a string.
eval([whatplot '(plots)'])
4 Commenti
Più risposte (2)
Patrick Kalita
il 21 Ott 2011
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 Commenti
Vedere anche
Categorie
Scopri di più su Interactive Control and Callbacks in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!