Saving the zoom in plot

4 vues (au cours des 30 derniers jours)
JA
JA le 20 Juil 2016
Modifié(e) : JA le 20 Juil 2016
I have a GUI where i plot my signal, I import the signal with 'getappdata', apply filter to the signal and plot it.
function slider1_Callback(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
%get slider value for frequency
sliderValue = get(handles.slider1,'Value');
%set editbox value
set(handles.edit1,'String',sliderValue)
%get the signal to be filtered
sig = getappdata(0,'signal');
%instantiate the filter class
f = ltiFilter.PT1();
%set the frequcny
f.fc = sliderValue;
%apply filter
for i = 1: length(sig)
updated(i).filter = f.eval(sig(i).signal,sig(i).signal(1));
end
for i = 1:length(sig)
plot(sig(i).time,sig(i).signal,sig(i).time,updated(i).filter)
hold on
end
hold off
legend('raw','filt');
This code works correctly, but the only problem is when i re-slide, it re-plots so i lose then zoom. and have to re zoom. So i retrieve the and restore the current zoom like this:
% retrieve the current zoom
tmp_xlim = get(handles.axes1, 'xlim');
tmp_ylim = get(handles.axes1, 'ylim');
for i = 1:length(sig)
plot(sig(i).time,sig(i).signal,sig(i).time,updated(i).filter);
hold on
end
hold off
legend('raw','filt');
% restore the zoom properties
set(handles.axes1, 'xlim', tmp_xlim);
set(handles.axes1, 'ylim', tmp_ylim);
Now the graph doesn't plot at all. Have no idea why. Any suggestions will be helpful.

Réponses (0)

Catégories

En savoir plus sur Data Exploration dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by