How to make dashed lines from dotted line commad whenever I changed '--' from ':'. I got solid lines intead of dashed lines

The code works fine but I want to changes dotted lines into dashed line (1st line solid and other lines in dashed form). I tried dashed line command '--' but I got Solid lines instead of dashed lines. I need help in this regard
function
clc
clf
clear all
close all
for i=1:5
Pr=1;
lambda=0.5;
k=[1 1.5 3 8 20];
We=0.1;
M=0.5;
C=0.5;
infinity=3;
solinit = bvpinit(linspace(0,infinity,100),[0 0 1 1 C 0 0 0]);
options = bvpset('stats','on');
sol = bvp4c(@ex8ode,@ex8bc,solinit,options, Pr, lambda, k(:,i), We, M, C);
eta = sol.x;
f = sol.y;
n=['-',':',':',':',':'];
j=['k','y','b','g','r'];
fprintf('\n');
plot(eta,f(2,:),n(:,i),'linewidth',1, 'color',j(:,i));
hold on
end
xlabel('\eta');ylabel('f^\prime(\eta)');
legend('K=1','K=1.5','K=3','K=8','K=20')
% --------------------------------------------------------------------------
function dfdeta = ex8ode(eta,f, Pr, lambda, k, We, M, C)
%EX8ODE ODE function for velocity profile.
dfdeta = [ f(2)
f(3)
(1/(1+We*f(3)))*(f(2).^2-f(1).*f(3)-f(4).*f(3)+M*f(2)+lambda*f(7)+(1/k)*f(2))
f(5)
f(6)
(1/(1+We*f(6)))*(f(5).^2-f(1).*f(6)-f(4).*f(6)+M*f(5)+(1/k)*f(5))
f(8)
-Pr*(f(1).*f(8)+f(4).*f(8))
];
% --------------------------------------------------------------------------
function res = ex8bc(f0,finf,Pr, lambda, k, We, M, C)
%EX8BC Boundary for velocity profile of williamson fluid.
res = [f0(1)
f0(4)
f0(7)-1
f0(2)-1
f0(5)-C
finf(2)
finf(5)
finf(7)
];

8 Comments

Your code seems incomplete (you have an end statement but no for statement), and it is not clear where i is being defined. It is also a bit hard to read your code because you did not use the formatting tools when you posted your question.
However, from what I can tell, it looks like you should be getting dashed lines, so my best guess is that your indexing variable (i) is not being set correctly. Could you update your code to include some sample data (and use the code formatting tools)? It may help others to answer your question.
here is a code para. it's working fine but I want to make dotted lines into Dashed lines but it didn't work me whenever I changed ':' to '--' . it's gives me solid lines
solinit = bvpinit(linspace(0,infinity,100),[0 0 1 1 C 0 0 0]);
options = bvpset('stats','on');
sol = bvp4c(@ex8ode,@ex8bc,solinit,options, Pr, lambda, k(:,i), We, M, C);
eta = sol.x;
f = sol.y;
n=['-',':',':',':',':'];
j=['k','y','b','g','r'];
fprintf('\n');
plot(eta,f(2,:),n(:,i),'linewidth',1, 'color',j(:,i));
hold on
end
xlabel('\eta');ylabel('f^\prime(\eta)');
legend('K=1','K=1.5','K=3','K=8','K=20')
Please post code that will produce an example. If we try running this code we will first get a syntax error, and then several errors due to missing variables.
here is my code: n=['-', ':'] is for dotted line but I want to make first line solid and all other lines in dashed form form better view
function
Invalid expression. Check for missing or extra characters.
clc
clf
clear all
close all
for i=1:5
Pr=1;
lambda=0.5;
k=[1 1.5 3 8 20];
We=0.1;
M=0.5;
C=0.5;
infinity=3;
solinit = bvpinit(linspace(0,infinity,100),[0 0 1 1 C 0 0 0]);
options = bvpset('stats','on');
sol = bvp4c(@ex8ode,@ex8bc,solinit,options, Pr, lambda, k(:,i), We, M, C);
eta = sol.x;
f = sol.y;
n=['-',':',':',':',':'];
j=['k','y','b','g','r'];
fprintf('\n');
plot(eta,f(2,:),n(:,i),'linewidth',1, 'color',j(:,i));
hold on
end
xlabel('\eta');ylabel('f^\prime(\eta)');
legend('K=1','K=1.5','K=3','K=8','K=20')
% --------------------------------------------------------------------------
function dfdeta = ex8ode(eta,f, Pr, lambda, k, We, M, C)
%EX8ODE ODE function for velocity profile.
dfdeta = [ f(2)
f(3)
(1/(1+We*f(3)))*(f(2).^2-f(1).*f(3)-f(4).*f(3)+M*f(2)+lambda*f(7)+(1/k)*f(2))
f(5)
f(6)
(1/(1+We*f(6)))*(f(5).^2-f(1).*f(6)-f(4).*f(6)+M*f(5)+(1/k)*f(5))
f(8)
-Pr*(f(1).*f(8)+f(4).*f(8))
];
% --------------------------------------------------------------------------
function res = ex8bc(f0,finf,Pr, lambda, k, We, M, C)
%EX8BC Boundary for velocity profile of williamson fluid.
res = [f0(1)
f0(4)
f0(7)-1
f0(2)-1
f0(5)-C
finf(2)
finf(5)
finf(7)
];
I ran the code in your comment. See the result?
  1. Try now it's complete with all respect.
function GhulamDastgeerVariationForK
clc
clf
clear all
close all
for i=1:5
Pr=1;
lambda=0.5;
k=[1 1.5 3 8 20];
We=0.1;
M=0.5;
C=0.5;
infinity=3;
solinit = bvpinit(linspace(0,infinity,100),[0 0 1 1 C 0 0 0]);
options = bvpset('stats','on');
sol = bvp4c(@ex8ode,@ex8bc,solinit,options, Pr, lambda, k(:,i), We, M, C);
eta = sol.x;
f = sol.y;
n=['-',':',':',':',':'];
j=['k','y','b','g','r'];
fprintf('\n');
plot(eta,f(2,:),n(:,i),'linewidth',1, 'color',j(:,i));
hold on
end
xlabel('\eta');ylabel('f^\prime(\eta)');
legend('K=1','K=1.5','K=3','K=8','K=20')
% --------------------------------------------------------------------------
function dfdeta = ex8ode(eta,f, Pr, lambda, k, We, M, C)
%EX8ODE ODE function for velocity profile.
dfdeta = [ f(2)
f(3)
(1/(1+We*f(3)))*(f(2).^2-f(1).*f(3)-f(4).*f(3)+M*f(2)+lambda*f(7)+(1/k)*f(2))
f(5)
f(6)
(1/(1+We*f(6)))*(f(5).^2-f(1).*f(6)-f(4).*f(6)+M*f(5)+(1/k)*f(5))
f(8)
-Pr*(f(1).*f(8)+f(4).*f(8))
];
% --------------------------------------------------------------------------
function res = ex8bc(f0,finf,Pr, lambda, k, We, M, C)
%EX8BC Boundary for velocity profile of williamson fluid.
res = [f0(1)
f0(4)
f0(7)-1
f0(2)-1
f0(5)-C
finf(2)
finf(5)
finf(7)
];
GhulamDastgeerVariationForK
The solution was obtained on a mesh of 100 points. The maximum residual is 2.649e-04. There were 3898 calls to the ODE function. There were 83 calls to the BC function.
The solution was obtained on a mesh of 100 points. The maximum residual is 3.088e-04. There were 3998 calls to the ODE function. There were 83 calls to the BC function.
The solution was obtained on a mesh of 100 points. The maximum residual is 7.754e-05. There were 3798 calls to the ODE function. There were 83 calls to the BC function.
The solution was obtained on a mesh of 100 points. The maximum residual is 6.246e-04. There were 2996 calls to the ODE function. There were 58 calls to the BC function.
The solution was obtained on a mesh of 80 points. The maximum residual is 2.262e-05. There were 4114 calls to the ODE function. There were 85 calls to the BC function.
function GhulamDastgeerVariationForK
for i=1:5
Pr=1;
lambda=0.5;
k=[1 1.5 3 8 20];
We=0.1;
M=0.5;
C=0.5;
infinity=3;
solinit = bvpinit(linspace(0,infinity,100),[0 0 1 1 C 0 0 0]);
options = bvpset('stats','on');
sol = bvp4c(@ex8ode,@ex8bc,solinit,options, Pr, lambda, k(:,i), We, M, C);
eta = sol.x;
f = sol.y;
n=['-',':',':',':',':'];
j=['k','y','b','g','r'];
fprintf('\n');
plot(eta,f(2,:),n(:,i),'linewidth',1, 'color',j(:,i));
hold on
end
xlabel('\eta');ylabel('f^\prime(\eta)');
legend('K=1','K=1.5','K=3','K=8','K=20')
end
% --------------------------------------------------------------------------
function dfdeta = ex8ode(eta,f, Pr, lambda, k, We, M, C)
%EX8ODE ODE function for velocity profile.
dfdeta = [ f(2)
f(3)
(1/(1+We*f(3)))*(f(2).^2-f(1).*f(3)-f(4).*f(3)+M*f(2)+lambda*f(7)+(1/k)*f(2))
f(5)
f(6)
(1/(1+We*f(6)))*(f(5).^2-f(1).*f(6)-f(4).*f(6)+M*f(5)+(1/k)*f(5))
f(8)
-Pr*(f(1).*f(8)+f(4).*f(8))
];
end
% --------------------------------------------------------------------------
function res = ex8bc(f0,finf,Pr, lambda, k, We, M, C)
%EX8BC Boundary for velocity profile of williamson fluid.
res = [f0(1)
f0(4)
f0(7)-1
f0(2)-1
f0(5)-C
finf(2)
finf(5)
finf(7)
];
end
I'm getting this result but I want to change dotted lines into dashed lines

Sign in to comment.

Answers (1)

The lines in your MATLAB plot are appearing solid instead of dashed due to how you're indexing the line styles and colors in your code. MATLAB treats n(:,i) and j(:,i) as indexing columns of a character array. Since '--' is two characters, MATLAB stores it as a 2D character array, and n(:,i) returns a column vector of characters, not a valid line style string.
To fix this:
  • Use cell arrays instead of character arrays
  • Update “plot”
Here is the updated code:
n={'-','--','--','--','--'};
j={'k','y','b','g','r'};
fprintf('\n');
plot(eta,f(2,:),n{i},'linewidth',1, 'color',j{i});
For more information on cell arrays refer to the link below:

Categories

Asked:

on 22 Jan 2021

Answered:

on 26 Jun 2025

Community Treasure Hunt

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

Start Hunting!