Why does the SEMILOGY function not plot onto a logarithmic scale in MATLAB 6.5 (R13)?

411 Ansichten (letzte 30 Tage)
Why does the SEMILOGY function not plot onto a logarithmic scale in MATLAB 6.5 (R13)?
Try the following lines of code:
y = rand(1, 20);
figure
hold
semilogy(1:20, y)
The resulting graph is plotted in a linear fashion and not in semi-log fashion. However, if I rearrange the order of the last two commands, the axes remains semilog.

Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 27 Jun. 2009
This is a bug in the documentation in MATLAB R13. This bug was fixed in MATLAB 7.4 (R2007a) to include the following statement in the help for LOGLOG, SEMILOGX/SEMILOGY function:
If you attempt to add a loglog, semilogx, or semilogy graph to a linear axis mode plot with hold on, the axis mode will remain as it is and the new data will plot as linear.
When the figure is created its axes are linear by default and executing a HOLD function after creating the figure locks the properties of the figure and also the axes.
The axes are set to 'log' with SEMILOGY function if it is executed before the HOLD command, therefore, you can use HOLD with SEMILOGY without setting the scale of the y-axis to 'log' as long as you execute SEMILOGY before HOLD, i.e.,
y = rand(1, 20);
figure
semilogy(1:20, y)
hold
Similarly, the POLAR and HOLD functions also behave in the same manner. In this case too, the POLAR function should be executed before the HOLD function to prevent plotting polar data on a linear scale.
  1 Kommentar
Steven Lord
Steven Lord am 5 Apr. 2022
This is not a bug.
The easiest way to get a logarithmic X and/or Y axes after enabling hold on is to change the XScale and/or YScale properties of the axes. While hold on may prevent MATLAB from automatically changing those properties, it does not prevent you from manually changing those properties. Compare the figures created by the two code segments below (and run the second of those code segments line by line to see the effect the last line has.)
figure
plot(1:10) % Y axis is created with a linear scale
hold on % Automatic changing of properties is disallowed
title('Linear Y axis is preserved by hold on')
semilogy(exp(1:10)) % This is not allowed to change the Y axis to a log scale
figure
plot(1:10) % Y axis is created with a linear scale
hold on % Automatic changing of properties is disallowed
title('Linear Y axis is preserved by hold on until the set call changes it')
semilogy(exp(1:10)) % This is not allowed to change the Y axis to a log scale
set(gca, 'YScale', 'log') % But you can explicitly force it to be logarithmic

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Mustafa qays
Mustafa qays am 13 Nov. 2017
Bearbeitet: Mustafa qays am 13 Nov. 2017
You can change it to semilogy at the end , even if you used plot instead of semilogy
y = rand(1, 20);
figure
hold
plot(1:20, y)
set(gca,'yscale','log')

Kategorien

Mehr zu Specifying Target for Graphics Output finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by