Changing exponential axis scale

I have a graph with x-axis scale e-6 but I want the scale to be e-9. When I use the code ax = gca and then ax.XAxis.Exponent = -9, the x-axis scale becomes e2147483647. How can I get the x-axis to become e-9? Please see code below.
c = 3e+08; % Speed of light in m/s
h = 6.63e-34; % Planck's constant in Js
k = 1.38e-23; % Boltzmann's constant in J/K
T = 5973.15; % Temperature in K
y = 0:10e-9:2000e-9; % Wavelength in m
R = ((2*pi*h*c^2)./y.^5).*(1./(exp((h*c)./(k*T*y))-1)); % Spectral Irridiance in W/m^2/m
plot(y,R)
xlabel({'Wavelength','(nm)'});
ylabel({'Spectral Irridiance','(W/m^2/nm)'});
title('Black Body Radiation Spectrum at 5700 Degrees Celcius');

 采纳的回答

I am not certain what the problem is.
The approach you took appears to work here (R2023b) —
c = 3e+08; % Speed of light in m/s
h = 6.63e-34; % Planck's constant in Js
k = 1.38e-23; % Boltzmann's constant in J/K
T = 5973.15; % Temperature in K
y = 0:10e-9:2000e-9; % Wavelength in m
R = ((2*pi*h*c^2)./y.^5).*(1./(exp((h*c)./(k*T*y))-1)); % Spectral Irridiance in W/m^2/m
plot(y,R)
xlabel({'Wavelength','(nm)'});
ylabel({'Spectral Irridiance','(W/m^2/nm)'});
title('Black Body Radiation Spectrum at 5700 Degrees Celcius');
ax = gca;
ax.XAxis.Exponent = -9;
.

3 个评论

Ok thanks. I am using MATLAB Online which is the latest version so I dont know either.
As always, my pleasure!
I just now ran it in MATLAB Online (R2023b). It worked correctly, giving the same results as depicted here.
MATLAB Online has the same version as MATLAB Answers i.e. R2023b. You should not have any problems there. (Type "ver" in the command window to check)
Also, @Craig, if the wavelength is in meters, and the unit of x-axis is nano-meter, the xtick values should be adjusted accordingly as well no.

请先登录,再进行评论。

更多回答(0 个)

类别

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by