GUI Hold on issue

13 ビュー (過去 30 日間)
Anas Abid
Anas Abid 2021 年 7 月 13 日
回答済み: Cris LaPierre 2021 年 7 月 14 日
Hello!
I'm trying to create a GUI, in short, i have an issue with one of my pushbutton functions.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global data1
plot(handles.axes1,data1(:,2),data1(:,5));
This works just fine and gives me my plot.
However, i'd like to add a horizontal line in the same plot, so i used this code :
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global data1
plot(handles.axes1,data1(:,2),data1(:,5));
hold on
plot(handles.axes1,[min(data1(:,2)) max(data1(:,2))],[0.2 0.2],'g-');
hold off
Which essentially draws a green line in the plot, when i compile(push the button), only the green line plots and the initial plot doesn't. I cannot figure this out, please help :).

回答 (1 件)

Cris LaPierre
Cris LaPierre 2021 年 7 月 14 日
See my answer here.
Short answer, in an app, you need to specify the target axes, just like you do in the plot command.
hold(handles.axes1,'on')
plot(handles.axes1,...)
hold(handles.axes1,'off')

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by