How can I use an edit text box to plot a function in a GUI?

6 ビュー (過去 30 日間)
Ian Hanken
Ian Hanken 2015 年 3 月 27 日
コメント済み: Adam 2015 年 3 月 28 日
Hello,
I've tried just about everything I can think of to take a function input from a text edit box in a GUI and plot it. Here's my code currently:
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
fct1 = get(handles.edit1,'string');
axes(handles.axes1);
plot(fct1)
I've tried various things, such as using str2func, messing with eval, etc. but nothing seems to work. Can someone help me out with correct syntax to make this happen?
Thanks!
SOLVED
Image Analyst helped me out and solved the issue:
Do a "whos" on it to see what it is. If it's a cell array, do this
ca = get(handles.edit1,'string');
whos ca
fct1 = char(ca);
whos fct1
axes(handles.axes1);
ezplot(fct1)

採用された回答

Image Analyst
Image Analyst 2015 年 3 月 27 日
Try ezplot() instead of plot. For example:
ezplot('sinc(x)')
  4 件のコメント
Ian Hanken
Ian Hanken 2015 年 3 月 28 日
Image Analyst, this solves my problem! Thanks. I don't know how to accept your answer, but I'll edit my top post!
Adam
Adam 2015 年 3 月 28 日
There's a big green thing that says "Accept Answer"!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by