How to make dashed lines from dotted line commad whenever I changed '--' from ':'. I got solid lines intead of dashed lines
5 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Walter Roberson
2021 年 1 月 23 日
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
回答 (1 件)
Harshavardhan
2025 年 6 月 26 日
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:
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Polynomials についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

