How to receive a function in MATLAB app DESIGNER given by user in edit field?
14 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
HI,
I am working on an app where user will put function and a value .output will be the value we get putting the input value in function.
such as, function will be
y=x^2+2^x+3
and x=2
how to code this??
0 commentaires
Réponse acceptée
Voss
le 6 Mai 2022
Something like this would work for functions of one variable, which is always called 'x'
% user inputs:
str = 'x^2+2^x+3'; % function, taken from an EditField
x = 2; % x value
f = str2func(['@(x)' str])
y = f(x) % output
To be more general than that, you'd have to modify this approach or do something else.
3 commentaires
Voss
le 7 Mai 2022
You're welcome! Glad it's working.
The code you shared just now looks like it will work, assuming:
- app.EditField is an EditField (i.e., a uieditfield of style 'text')
- app.EditField2 is a NumericEditField (i.e., of style 'numeric' - if not, you can use str2double to convert x to a number), and
- app.EditField3 is an EditField (again, of style 'text' - if not, you can avoid converting y to a string with num2str and use the numeric value of y directly).
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!