Saving the zoom in plot

5 次查看(过去 30 天)
JA
JA 2016-7-20
编辑: JA 2016-7-20
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.

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Exploration 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by