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

335 次查看(过去 30 天)
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.

采纳的回答

MathWorks Support Team
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 个评论
Steven Lord
Steven Lord 2022-4-5
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

请先登录,再进行评论。

更多回答(1 个)

Mustafa qays
Mustafa qays 2017-11-13
编辑:Mustafa qays 2017-11-13
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')

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by