How to change the x-axis so you only view the image (axistight)?

4 次查看(过去 30 天)
Hi! I am looking how I can change my x-axis limits so I will only view the area of interest on the figure?
The code below is used: To load the data: for i = 1:10; c3dFile_i = sprintf('GaitData_subject_%d.c3d',i); [Markers(i).subject,MLabels(i).subject,VideoFrameRate(i).subject,AnalogSignals(i).subject,ALabels(i).subject,AUnits(i).subject,AnalogFrameRate(i).subject,Event(i).subject,ParameterGroup(i).subject,CameraInfo(i).subject]=readC3D(c3dFile_i); end
To plot the GRF: for i = 1:10 fs = 1000; if i==1 i==2 i==3 i==8 i==10 for j = 1:3 GRF_i = abs(AnalogSignals(i).subject(:,j)); n = 2; fcutoff = 5; Wn = fcutoff/(fs/n); [B,A] = butter(n,Wn,'low'); GRF_filt = filtfilt(B,A,GRF_i);
figure(i);
xlim([0 xlabel_end(n)]);
subplot(3,1,j);
plot(GRF_filt, 'b', 'LineWidth', 1);
xlabel('time[s]');
for n = 1:10
xlabel_end(n) = length(AnalogSignals(n).subject)/1000;
end
ylabel('F[N]');
if j == 1
title(['x component of filtered GRF of subject ', num2str(i)]);
elseif j == 2
title(['y component of filtered GRF of subject ', num2str(i)]);
else
title(['z component of filtered GRF of subject ', num2str(i)]);
end
end
else
GRF_i = abs(AnalogSignals(i).subject(:,25:27));
for k = 25:27
n = 2;
fcutoff = 5;
Wn = fcutoff/(fs/n);
[B,A] = butter(n,Wn,'low');
GRF_filt = filtfilt(B,A,abs(AnalogSignals(i).subject(:,k)));
figure(i);
subplot(3,1,(k-24));
plot(GRF_filt, 'b', 'LineWidth', 1);
xlabel('time[s]');
for n = 1:10
xlabel_end(n) = length(AnalogSignals(n).subject)/1000;
end
ylabel('F[N]');
if j == 1
title(['x component of filtered GRF of subject ', num2str(i)]);
elseif j == 2
title(['y component of filtered GRF of subject ', num2str(i)]);
else
title(['z component of filtered GRF of subject ', num2str(i)]);
end
end
end
end
Thanks in advance if anyone could help!

回答(1 个)

Benjamin Kraus
Benjamin Kraus 2017-12-28
There are a few ways to change the x-axis limits:
xlim([-inf inf]) % Fit the x-limits tight to the data.
axis tight % Fit x, y, and x-limits tight to the data.
xlim([0 xlabel_end(n)]); % Hard-code the limits
That last command is copied from your code, but you are setting the limits before you plot instead of after you plot. The plot command resets the axes properties (including the limits) to the default values. If you move the call to xlim after the call to plot, I think you will get the desired effect.
subplot(3,1,j);
plot(GRF_filt, 'b', 'LineWidth', 1);
xlim([0 xlabel_end(n)]);
  2 个评论
Lore Vleugels
Lore Vleugels 2017-12-29
Hi! Thank you very much for your extensive answer! I have tried all three options, but none of them change the axis limits of the x-axis unfortunately. If I run the code, I still get the same image as shown below. I need the range from approximately 750ms till 1600ms. Is there another way to change the axis limits?
Benjamin Kraus
Benjamin Kraus 2017-12-29
If you need specific limits, then just provide those as input to xlim:
xlim([750 1600])

请先登录,再进行评论。

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by