GUI Hold on issue

21 views (last 30 days)
Anas Abid
Anas Abid on 13 Jul 2021
Answered: Cris LaPierre on 14 Jul 2021
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 :).

Answers (1)

Cris LaPierre
Cris LaPierre on 14 Jul 2021
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')

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!