How to make dashed lines from dotted line commad whenever I changed '--' from ':'. I got solid lines intead of dashed lines
Mostrar comentarios más antiguos
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 comentarios
Benjamin Kraus
el 22 de En. de 2021
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.
Ghulam Dastgeer
el 23 de En. de 2021
Rik
el 23 de En. de 2021
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.
Rik
el 23 de En. de 2021
I ran the code in your comment. See the result?
Ghulam Dastgeer
el 23 de En. de 2021
GhulamDastgeerVariationForK
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
Ghulam Dastgeer
el 23 de En. de 2021
Respuestas (1)
Harshavardhan
el 26 de Jun. de 2025
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:
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

