MATLAB Answers

Why does not semilogy works?

3 views (last 30 days)
Ove Gustafsson
Ove Gustafsson on 10 May 2021
Commented: Ove Gustafsson on 10 May 2021
Printing semilogy and loglog and the gca indicate that no log x- or y-scale ar set
XScale: 'linear'
YScale: 'linear'
Do I have to go into the gca everyttime I would like to plot a log figure?
  2 Comments
Ove Gustafsson
Ove Gustafsson on 10 May 2021
Thank you for the answer. Down below you see an example of the type of simple code. I guess that you understand the meaning.
figure(1);
hold on
nnmax= size(data.file,1);
for kk=1:1:nnmax
semilogy(data.x(:,kk), data.y(:,kk));
end
hold off
I understand that I have to move the "hold on" comand somewhere. It works when I give the comand for the first line infront of the for-loop. The simple test with an other version works, code as you see below.
figure(2);
nnmax= size(data.file,1);
kk=1;
semilogy(data.Wavelength(1:data.numberline(kk),kk), data.Reflex(1:data.numberline(kk),kk));
hold on
for kk=2:1:nnmax
semilogy(data.Wavelength(1:data.numberline(kk),kk), data.Reflex(1:data.numberline(kk),kk));
end
hold off

Sign in to comment.

Answers (2)

Walter Roberson
Walter Roberson on 10 May 2021
loglog() and semilogy() and semilogx() have no effect if "hold on" is already in effect for the axes. You cannot mix log coordinates and linear coordinates in the same axes.
  1 Comment
Ove Gustafsson
Ove Gustafsson on 10 May 2021
Thank you for this information!
Best regardes
Ove

Sign in to comment.


VBBV
VBBV on 10 May 2021
Edited: VBBV on 10 May 2021
%if true
figure(1);
%hold on
nnmax= size(data.file,1);
for kk=1:1:nnmax
semilogy(data.x(:,1:kk), data.y(:,1:kk));
end
%ld off
try also this way
  1 Comment
Ove Gustafsson
Ove Gustafsson on 10 May 2021
Hi VBBV!
Both versions work well! I have always used "hold on" etc but it seems to work without that command line sometimes.
Thank you for the answer!

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!