How to take function as input from textbox?

how can I take a function such as sin(x) or exp(x) as an input from the textbox in MATLAB gui?
t = get(handles.input,'string')
c = conv (t,t)
plot(c)
I have tried this but it does not work.
I want to convolve the signal but I can't figure out how to take input as a function

4 comentarios

Mehmed Saad
Mehmed Saad el 6 de Mayo de 2020
do you mean user enters sin(x) or exp(x) in textbox or user enters the values like 1 2 3 4?
Saad Rana
Saad Rana el 6 de Mayo de 2020
I mean that the user enter sin(x) or cos(x) or exp(x) and functions like that
Mehmed Saad
Mehmed Saad el 6 de Mayo de 2020
and do you have x or user have to enter it? is it necessary to use text box (you can use dropdown)?
Saad Rana
Saad Rana el 6 de Mayo de 2020
yes I have a user to enter it and the textbox is necessary

Iniciar sesión para comentar.

Respuestas (1)

Mehmed Saad
Mehmed Saad el 6 de Mayo de 2020
You can use any one of the following
  1. eval
  2. feval
  3. str2func
For example
The string user enters in text box is
s = 'sin(x)';
eval will evaluate the string assuming that x is variable inside your function workspace in which you are evaluation eval
eval(s)
For feval and str2func user must enter the function name and not the argument
s = 'sin'
feval(s,x)
or
s = 'sin';
f = str2func(s);
f(x)

Categorías

Más información sobre Get Started with MATLAB en Centro de ayuda y File Exchange.

Preguntada:

el 6 de Mayo de 2020

Respondida:

el 6 de Mayo de 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by