get a input function in GUI
이전 댓글 표시
if i input a function,eg.t^2, in the edit,how could i get the function in the M file? and when i type f=fourier(sin(t))*fourier(cos(t)) in the command window, it will show error "??? Undefined function or variable 't'.", how to solve this problem? Thank you~~~
답변 (2개)
Paulo Silva
2011년 4월 16일
a=get(handles.text1,'String'); %get the string from the textbox,example %a='t^2';
b=vectorize(a); %put dots before operations ^ / *
c=inline(b); %create one inline function from the string
t=0:0.1:10; %create a time vector, starts in t=0, step 0.1 seconds, ends t=10 s
c(t); %evaluate your function at each time vector point
For the fourier problem, t should be defined like a symbolic variable before the function being called
syms t
댓글 수: 2
José
2011년 11월 20일
I've tried your answer, but I've get some errors.
??? Error using ==> sym.sym>tomupad at 2209
Conversion to 'sym' from 'inline' is not possible.
Error in ==> sym.sym>sym.sym at 111
S.s = tomupad(x,'');
Error in ==> subs at 64
r_unique_name = subs(sym(f_unique_name),varargin{:});
I'm also trying to input a function in an edit text from the GUI.
Thank you for your help.
yo yoo
2016년 8월 12일
I tried your answer to introduce functions, and it worked, thank you
Olaitan Ibrahim
2018년 7월 27일
0 개 추천
Hello, pls I'm trying to use a get method in my gui program but I don't want all my inputs to remain in the edit box. Guys please help me out.
댓글 수: 1
Walter Roberson
2018년 7월 27일
Please start a new Question for that topic, and be sure to include relevant code.
카테고리
도움말 센터 및 File Exchange에서 Common Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!