How to cut off part of the figure out after you filtered it

3 次查看(过去 30 天)
Hello, I'm trying to cut out part of my plot but I dont know how I could modify the script to cut it out and here is what I got so far after I apply a lowpass filter.
Thank you for your time
Ts = 0.01;
Fs = 1/Ts;
Fm = Fs/2;
Fc = 2;
N =10;
d = fdesign.lowpass('N,Fc',N,Fc,Fs);
designmethods(d);
Hd = design(d);
%fvtool(Hd)
%X is a variable form csv
%X1 is a variable from csv
output = filter(Hd,X);
output1 = filter(Hd,X1);
figure;
plot(X,X1,'-g');
hold on
plot(output, output1,'r');
hold off
legend('raw signal','filtered signal')
xlabel('SWA (deg)')
ylabel('SWT (N.m)')
title('SWA vs SWT')
grid on
figure
subplot(2,1,1)
plot(X,X1);
title('Original plot');
uiwait(msgbox('Select an x-value from which to crop','modal'));
[x_user ~] = ginput(1); % Let the user select an x-value from which to crop.
x(x>x_user) = [];
subplot(2,1,2);
plot(output, output1);
title('New plot with cropped values');
xlim([min(x(:)) max(x(:))]);

回答(1 个)

Image Analyst
Image Analyst 2021-2-12
You could just display from 100 on:
xlim([100, max(output1)]);
or you could remove everything less than x=100
startingIndex = find(x >= 100, 1, 'first');
output = output(startingIndex : end);
output1 = output1(startingIndex : end);
X = X(startingIndex : end);
X1 = X1(startingIndex : end);
Of course you could use max(x_user) instead of 100 if you want.
  8 个评论
nam bui
nam bui 2021-2-15
please let me know, what should I fix, I have attached the mat file. Thank you
Image Analyst
Image Analyst 2021-2-15
Look, sample.mat does not have a "current" variable stored in it.
sample = load('sample.mat')
sample =
struct with fields:
sample: [1500×2 table]
Reference to non-existent field 'current'.
Error in test6 (line 10)
X = sample.current;
You need to use a .mat file that has both current and sample variables in it.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Grid Lines, Tick Values, and Labels 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by