
Only part of my plotted line will dash, the rest is solid. Any help?
9 views (last 30 days)
Show older comments
Hi all,
I'm currently trying to plot the change in output of an ODE as a parameter is made larger. I have the plots working fine but if I try to dash one of the lines then it only does part of it.
I'll attach the code below, although its quite rough and ready as I threw it together and haven't had much of a chance to optimise it.
function program;
tic;
xd = [2.99 2.99];
yd = [1e-20 1e-10];
xd1 = [0.314 0.315];
logs = logspace(-2,2,100);
ic1 = [1.32e-13 (2.65e-14/2) 0 ((1.375e-14)/2) 0];
ic2 = [4*1.32e-13 (2.65e-14/2) 0 ((1.375e-14)/2) 0];
tg = [0:0.1:5];
global kg k450;
for i= 1:100;
kg = logs(i);
k450 = 0.315;
options = odeset('RelTol',1e-18,'AbsTol',1e-19);
[t y]=ode15s(@model,tg,ic1,options);
kg1(i)=kg;
c1(i)=min(y(:,4));
end;
for i= 1:100;
kg = logs(i);
k450 = 0.315;
options = odeset('RelTol',1e-20,'AbsTol',1e-20);
[t y]=ode15s(@model,tg,ic2,options);
kg2(i)=kg;
c2(i)=min(y(:,4));
end;
for i= 1:100;
k450 = logs(i);
kg=2.99;
options = odeset('RelTol',1e-21,'AbsTol',1e-21);
[t y]=ode15s(@model,tg,ic1,options);
k4501(i)=k450;
c3(i)=min(y(:,4));
end;
for i= 1:100;
k450 = logs(i);
kg = 2.99;
options = odeset('RelTol',1e-22,'AbsTol',1e-22);
[t y]=ode15s(@model,tg,ic2,options);
k4502(i)=k450;
c4(i)=min(y(:,4));
end;
clf;
subplot(1,2,1);
loglog(kg1,c1);
hold on;
loglog(kg2,c2,'LineStyle', '--');
line(xd,yd);
subplot(1,2,2);
loglog(k4501,c3);
hold on;
loglog(k4502,c4,'LineStyle', '--');
line(xd1,yd);
function yp=model(t,y)
dgsh = 2;
bgsh = 1.375e-14;
kgsh = 1.6e18;
ks = 2.26e14;
bs = 2.65e-14;
ds = 2;
kn = 0.0315;
kpsh = 1;
P=y(1);
S=y(2);
N=y(3);
G=y(4);
C=y(5);
yp1 = -ks*S*P - kg*P - k450*P + kn*N;
yp2 = -ks*S*P + bs - ds*S;
yp3 = k450*P - kn*N - kgsh*N*G - kpsh*N;
yp4 = -kgsh*N*G + bgsh - dgsh*G;
yp5 = kpsh*N;
yp=[yp1; yp2; yp3; yp4; yp5];
end
toc;
end
The 2 lines produced with the LineStyle command are only partially dashed, the rest of the line is solid. Any help would be much appreciated
3 Comments
Image Analyst
on 16 Jan 2015
Since Mike works for the Mathworks I'd bet it was the latest release (R2014b). I'm also using R2014b and I get the same plot as Mike - the dashed line is dashed the entire length of it. We're still waiting for you to post your screenshot.
Answers (2)
J S
on 22 Aug 2015
Edited: J S
on 22 Aug 2015
I see the same issue issue using Matlab R2014b 8.4.0.150421 opengl rendering on linux. The problem afflicts dashed (--), dotted (:), and dash-dotted (-.). Log-log plots using line (-) or symbols (o) are fine. See the attached plot showing the exact same data plotted using a line and then dashed.

0 Comments
J S
on 22 Aug 2015
Edited: J S
on 22 Aug 2015
As it happens, I immediately stumbled on a work around. My x-data had binning of "one", ie 1:1:2e5. I sparsified the data with logspacing to use marker 'o' in place of dashes and found the dashes worked. Here's my sparsified data:
% Create a cut on only good log-spaced x-values
MIN_VALUE = 2;
MAX_VALUE = 5e4;
NUM_POINTS = 200;
cc = unique(round( logspace(log10(MIN_VALUE), log10(MAX_VALUE), NUM_POINTS) ));
loglog(xdata(cc), ydata(cc), 'k--'); % <-- This works
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!