Coding for different x-axis increments
显示 更早的评论
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');
回答(2 个)
Star Strider
2019-11-25
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
2019-11-25
Use the xticks function:
xticks(f);
类别
在 帮助中心 和 File Exchange 中查找有关 Subplots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!