How to change the x-axis so you only view the image (axistight)?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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!
0 commentaires
Réponses (1)
Benjamin Kraus
le 28 Déc 2017
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 commentaires
Benjamin Kraus
le 29 Déc 2017
If you need specific limits, then just provide those as input to xlim:
xlim([750 1600])
Voir également
Catégories
En savoir plus sur Annotations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!