How to make dashed lines from dotted line commad whenever I changed '--' from ':'. I got solid lines intead of dashed lines
조회 수: 6 (최근 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!

