필터 지우기
필터 지우기

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

조회 수: 257 (최근 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
MathWorks Support Team 2009년 6월 27일
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에서 Specifying Target for Graphics Output에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by