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

4 ビュー (過去 30 日間)
Lore Vleugels
Lore Vleugels 2017 年 12 月 28 日
コメント済み: Benjamin Kraus 2017 年 12 月 29 日
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 Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by