GUI Hold on issue

22 visualizaciones (últimos 30 días)
Anas Abid
Anas Abid el 13 de Jul. de 2021
Respondida: Cris LaPierre el 14 de Jul. de 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 :).

Respuestas (1)

Cris LaPierre
Cris LaPierre el 14 de Jul. de 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')

Categorías

Más información sobre Graphics Object Programming en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by