How to take function as input from textbox?
조회 수: 4 (최근 30일)
이전 댓글 표시
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
Mehmed Saad
2020년 5월 6일
and do you have x or user have to enter it? is it necessary to use text box (you can use dropdown)?
답변 (1개)
Mehmed Saad
2020년 5월 6일
You can use any one of the following
- eval
- feval
- 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)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!