MATLAB: Can you tell me why the x-axis grid in plot (b) shows incorrectly

MATLABsubplot

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.

Best Answer

HG engine determines in default size there isn't enough room for the tick labels so defaults to the three values. Tick labels are duplicated for the number of total ticks by reusing the same array over from the top which gives the result obtained.
Looks like a bit of an oversight internally; if I use the default figure size here w/ R2012b (HG1, not HG2), on this monitor there's only the three ticks initially. If I expand the window width it gets redrawn with 5 ticks but the tick labels don't get updated to match and I get your symptom.
The solution is to create the figure large enough to be able to display all those digits if that's what you want and/or set the tick marks and labels explicitly, don't rely on the default behavior for such an extreme case (I find trying to read that as is very difficult; I can't count the zeros to know just what the actual frequency is without a whole lot of effort).
Alternatively, as Star-S says, you might try setting the default font size smaller before the creation and see if that is taken into account in the calculations internally but still I think the solution is to set ticks and labels explicitly (altho again I'd agree w/ Star as noted above and go with the exponential notation here).