Saving a figure in matlab with zoom functionality
Show older comments
I have a code that generates a plot of my original signal, the rectified signal and then a liner envelpe of the signal. I would like to be able to zoom in on any plot(currently i think my code sets it to the original but if it can be modified to be any plot then if anyone knows how to do that i would apprecate it) and have the other two plots zoom in to the same point automatically. My below code currently does tht if you zoom in on the original signal. I wish to save the figure and then have that zoom funcitonality still be active for the figure. I tried a few things but they didn't work. I'm not very familiar with matlab but i imagine that for it to have the zoom funcitonality you would need to run a script to open the figure with said functionality. If anyone can help out with that part of the code, it would be greatly apprecated. Thank you for your time in advance!
% Plot the original signal, rectified signal, and smoothed signal
figure;
h1 = subplot(3,1,1);
plot(t, original_signal);
title('Original Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
h2 = subplot(3,1,2);
plot(t, rectified_signal);
title('Rectified Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
h3 = subplot(3,1,3);
plot(t, smoothed_signal);
title('Linear Envelope');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
% Set the same x-axis limits for all subplots
common_xlim = [min(t), max(t)]; % Set x-axis limits to min and max of original signal
set(h1, 'XLim', common_xlim);
set(h2, 'XLim', common_xlim);
set(h3, 'XLim', common_xlim);
% Add zoom callback to the original signal subplot
hZoom = zoom;
hZoom.ActionPostCallback = @(obj,event_obj) set([h1,h2,h3],'XLim',get(event_obj.Axes,'XLim'));
Accepted Answer
More Answers (0)
Categories
Find more on Axis Labels 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!