Coding for different x-axis increments
Show older comments
My code is as follows: How do I make it so the respective plots will have x-axis increments of 1.25 instead of 1?
g=[0 5 0 0 -10 100 -10 0 0 0 10 0 0 0 0 0];
N=16;
G=fft(g);
A=2*abs(G(1:9))/N;
phi=angle(G(1:9))*180/pi;
A(1)=abs(G(1))/N;
f=[0:1.25:10];
plot(f,A,f,A,'o');
xlabel('frequency (Hz)');
ylabel('amplitude A');
title('Amplitude of Fourier Transform');
figure
plot(f,phi,f,phi,'o');
xlabel('frequency (Hz)');
ylabel('phase (deg)');
title('Phase of Fourier Transform');
Answers (2)
Star Strider
on 25 Nov 2019
Use the ‘f’ vector to define the 'XTick' locations:
set(gca, 'XTick',f)
Full code:
g=[0 5 0 0 -10 100 -10 0 0 0 10 0 0 0 0 0];
N=16;
G=fft(g);
A=2*abs(G(1:9))/N;
phi=angle(G(1:9))*180/pi;
A(1)=abs(G(1))/N;
f=[0:1.25:10];
plot(f,A,f,A,'o');
xlabel('frequency (Hz)');
ylabel('amplitude A');
title('Amplitude of Fourier Transform');
set(gca, 'XTick',f)
figure
plot(f,phi,f,phi,'o');
xlabel('frequency (Hz)');
ylabel('phase (deg)');
title('Phase of Fourier Transform');
set(gca, 'XTick',f)
Image Analyst
on 25 Nov 2019
Use the xticks function:
xticks(f);
Categories
Find more on Subplots 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!