Can you tell me why my x-axis grid in plot (b) shows incorrectly?
古いコメントを表示
Hello,
In my MWE below, I am plotting 4 graphs. I am trying to get graph (c) and (d) to show up with the x-axis as floating numbers, however I do not display the correct values for the x-axis points. If I put a break point in my program at line 23, and step through the program, it works without any problems. Can you tell me why I get an incorrect x-axis display if the program is run normally?
Here is my code:
clear;
clc;
x1 = linspace(100, 10^7, 100);
y1 = rand(100,1);
y2 = rand(100,1);
y3 = randi([-100,100],100,1);
subplot(2,2,1);
plot(x1, y1);
grid on;
title('(a) Silent Carrier (No Modulation)');
xlabel('Frequency (MHz)'); ylabel('Amplitude');
subplot(2, 2, 2);
plot(x1, y1);
grid on;
title('(b) Spectrum with Modulation');
xlabel('Frequency (MHz)'); ylabel('Amplitude');
subplot(2,2,3);
semilogx(x1, y2);
grid on;
title('(c) SSB Spectrum (Silent Carrier - NO Modulation)');
xlabel('Frequency Offset (Hz)'); ylabel('Phase Noise (dBc/Hz)');
curtick = get(gca, 'XTick');
set(gca, 'XTickLabel', cellstr(num2str(curtick(:))));
subplot(2,2,4);
semilogx(x1, y3);
grid on;
curtick = get(gca, 'XTick');
set(gca, 'XTickLabel', cellstr(num2str(curtick(:))));
title('(d) SSB Spectrum with Modulation');
xlabel('Frequency Offset (Hz)'); ylabel('Phase Noise (dBc/Hz)');
This is what I get for graphs (c) and (d):

and the "curtick" only has values [1 100000 10000000000.0000].
When it should be like:

I've recently found that if I leave the figure window open, in full screen, and re-run the program, it works. If I close the figure widow, and let it open up with the program, it comes in looking like the first figures.
2 件のコメント
Star Strider
2015 年 10 月 21 日
編集済み: Star Strider
2015 年 10 月 21 日
What do you want it to show? The full floating-point x-axis labels display correctly for me (although they run together). You can also use 'FontSize' in the set call to change the font size of the numbers in the x-ticks if you want to make them more readable, and in the more recent MATLAB releases, you can also rotate them.
(I would use the default exponent x-tick labels in this instance because of the magnitude of the tick labels in R2015b.)
monkey_matlab
2015 年 10 月 22 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Axis Labels についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!