Semilogy not plotting onto log scale MATLAB R2017b
Show older comments
I'm supposed to submit a script to uni and one of the questions asked to plot Temperature against Time on a logarithmic scale but for some reason I can't get it to work.
% code
Time = [0;620;2266;3482];
Temperature = [62;56;40;32];
subplot(1,2,1)
plot(Time, Temperature,'-o');
subplot(1,2,2)
semilogy(Time, Temperature,'-o')
end
but the second subplot always appears with rectilinear scales.
However when I change the variables around so that it's
% code
Time = [0;620;2266;3482];
Temperature = [62;56;40;32];
subplot(1,2,1)
plot(Temperature, Time,'-o');
subplot(1,2,2)
semilogy(Temperature, Time,'-o')
end
It does show a log scale.
I know that the second one is not correct as according to the question it should roughly align with the function T(t) = b × (10)^mt where T=temperature and t=time.
Answers (1)
Star Strider
on 7 Jan 2018
It is plotting correctly.
Try this, that includes a third subplot that does a linear plot of the log of ‘Temperature’:
figure(3)
Time = [0;620;2266;3482];
Temperature = [62;56;40;32];
subplot(1,3,1)
plot(Time, Temperature,'-o');
grid
subplot(1,3,2)
semilogy(Time, Temperature,'-o')
grid
subplot(1,3,3)
plot(Time, log10(Temperature),'-o')
yt = get(gca, 'YTick')
set(gca, 'YTick',yt, 'YTickLabel',10.^yt, 'YLim',log10([32 62]))
grid
Categories
Find more on Subplots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!