フィルターのクリア

hi guys, i want to plot in GUI, i've tried this code.

1 回表示 (過去 30 日間)
Anisio Gomes
Anisio Gomes 2016 年 1 月 3 日
コメント済み: Anisio Gomes 2016 年 1 月 6 日
function calcbutton_Callback(hObject, eventdata, handles)
dis = sqrt((handles.mydata.b)^2 -4*(handles.mydata.a)*(handles.mydata.c));
ans1 = (-(handles.mydata.b) + dis) /(2*(handles.mydata.a));
ans2 = (-(handles.mydata.b) - dis) /(2*(handles.mydata.a))
set(handles.ans1, 'String', ans2);
set(handles.ans2, 'String', ans1);
function plotbutton_Callback(hObject, eventdata, handles)
x=0:10;
plot(x,handles.ans1, handles.axes1);
hold on;
plot(x,handles.ans2, handles.axes2);
But it displays:
Error using plot
Data must be a single matrix Y or a list of pairs X,Y.

採用された回答

Image Analyst
Image Analyst 2016 年 1 月 3 日
編集済み: Image Analyst 2016 年 1 月 3 日
Get rid of the calls to set and just do this:
handles.ans1 = (-(handles.mydata.b) + dis) /(2*(handles.mydata.a));
handles.ans2 = (-(handles.mydata.b) - dis) /(2*(handles.mydata.a))
In the second callback do this instead:
x=0:(length(handles.ans1) - 1);
plot(x,handles.ans1, handles.axes1);
grid on;
hold on;
x=0:(length(handles.ans2) - 1);
plot(x,handles.ans2, handles.axes2);
If it still doesn't work, then find a call to guidata() somewhere in your code and copy it to the last line of the callback that assigns handles.ans1 and handles.ans2.
  4 件のコメント
Image Analyst
Image Analyst 2016 年 1 月 3 日
There's something you're not showing us. Attach the .m file and the .fig file, and any data files it reads in.
Anisio Gomes
Anisio Gomes 2016 年 1 月 3 日
編集済み: Anisio Gomes 2016 年 1 月 3 日
I attached the m,fig,jpg files

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

その他の回答 (1 件)

Anisio Gomes
Anisio Gomes 2016 年 1 月 3 日
Thanks Image Analyst... I've tried
function calcbutton_Callback(hObject, eventdata, handles)
dis = sqrt((handles.mydata.b)^2 -4*(handles.mydata.a)*(handles.mydata.c));
handles.ans1 = (-(handles.mydata.b) + dis) /(2*(handles.mydata.a));
handles.ans2 = (-(handles.mydata.b) - dis) /(2*(handles.mydata.a))
function plotbutton_Callback(hObject, eventdata, handles)
x=0:(length(handles.ans1) - 1);
plot(x,handles.ans1, handles.axes1);
grid on;
hold on;
x=0:(length(handles.ans2) - 1);
plot(x,handles.ans2, handles.axes2);
guidata(hObject, handles)
However, the error keep showing up..... :(
  3 件のコメント
Image Analyst
Image Analyst 2016 年 1 月 4 日
Let us know if it's fixed now.
Anisio Gomes
Anisio Gomes 2016 年 1 月 6 日
I've tried it and the problem remain here is the files

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

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by