Limit x-axis to specific values in GUI
12 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Robert Eisenbecker
el 23 de Oct. de 2017
Comentada: Robert Eisenbecker
el 24 de Oct. de 2017
Hello, I have a pushbutton which plots any function the user typed in an editable text. I also have two sliders, slider1 and slider2, who should dictate the limits of the x-axis of my plot. So slider1 should give the lower bound and slider2 the upper bound of the x-axis to display. My code doesn't work, I hope someone can help me with this:
% --- Executes on button press in pushbutton1.
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)
f = get(handles.edit1, 'string')
x = 0:0.1:1;
m = get(handles.slider1, 'Value')
n = get(handles.slider2, 'Value')
set(handles.axes1, 'XLim', [m, n])
axes(handles.axes1)
plot(eval(f))
Thank you!
7 comentarios
Respuestas (1)
Jan
el 24 de Oct. de 2017
Avoid setting the current axes actively. Better define the parent object to draw in:
% Instead of
axes(handles.axes1)
plot(eval(f))
% use
plot(handles.axes1, eval(f))
Is the 'NextPlot' property of the axes set to 'add'? This is equivalent to hold('on'). Otherwise a plot() command might reset the limits.
If the plot vanishes when the sliders are used, it sounds, like the problem is in the slider's callback, not in the one of the pushbutton.
Ver también
Categorías
Más información sobre Annotations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!