Clear Filters
Clear Filters

How to get a line plot without markers, on a logarithmic scale in a for loop?

3 views (last 30 days)
I want to express my reuslts from a for loop on a logaritmic scale (on x-axis). However, I am having trouble in getting both the logarithmic displays and line plots in one go.
  1. With the semilogx: display in logarithmic scale is achieved but only if I identify a marker such as 'o' or 's'. However, I can't get it to plot show the results as a line or a line plot.
  2. With the addpoints approach: Sure, I get a line plot. Still, in this case I am unable to solve the other problem of displaying on a logarithmic scale.
To keep the script brief, I am leaving out the constants I used. You can put in random values for execution. This is my for loop:
t=1:10000;
for i=1:numel(t)
f2=(v293/v)^(10*(alpha^4));
f1=1+((1-alpha)^2)*log(350/Blaine);
n=nzero*f1*f2;
etaalpha=exp(-n*alpha);
Aalpha=k*(A/((k*alphau)+alpha))*(alphau-alpha);
alpha=Aalpha*etaalpha*exp(-EA/(R*T))*exp(EA/(R*293))+alpha;
semilogx(i,alpha,'o-'); % outputs a logarithmic x-axis with markers (sadly not a line)
hold on
% hold all
% addpoints(h,t(i),alpha(1)) % outputs a line plot
% drawnow limitrate
end
  3 Comments
dpb
dpb on 27 Jun 2021
semilogx(i,alpha,'o-');
You told it to NOT use a line but only a marker.
See the doc for linestyle triplets for the details.

Sign in to comment.

Answers (1)

Scott MacKenzie
Scott MacKenzie on 27 Jun 2021
Edited: Scott MacKenzie on 27 Jun 2021
As noted clearly by @dpb, you need to not use the 'o-' syntax to get the lines without markers:
i = 1:10;
alpha = rand(1,10);
tiledlayout('flow');
nexttile;
semilogx(i,alpha,'o-'); % your code: line+maker
nexttile;
semilogx(i,alpha); % line only (i.e., no marker)
  6 Comments
Mansoor Aziz
Mansoor Aziz on 30 Jun 2021
I just ended up initiating and filling up another vector. That vector was plotted against time outside the for-loop.
for i=1:numel(t)
.
.
.
alpha=Aalpha*etaalpha*exp(-EA/(R*T))*exp(EA/(R*293))+alpha;
Aplot(end+1)=alpha;
end
semilogx(t,Aplot)
Scott MacKenzie
Scott MacKenzie on 1 Jul 2021
Yes, that should work, provided t and Aplot are vectors of the same length. You can also just use
semilogx(Aplot)
as noted in my previous comment.
BTW, here is the documentation on the use of semilogx when ommitting the 1st argument, X:

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!