MATLAB Answers

How can I change the line color in a graph using plot

1 view (last 30 days)
Muhammad Fauzan
Muhammad Fauzan on 28 Jul 2021
Edited: Stephen on 28 Jul 2021
I got a different plot from the video tutorial, but the code is exactly the same. anyone can help me?
This is the plot of the code I made
Meanwhile, this is the plot of the video tutorial
and this is the code
Dy = 10; Dz = 10;
lambda = 0.0001;
a = 270;
v = 3;
Q1 = 1000;Q5 = 1000;Q9 = 1000;
Q2 = 1000;Q6 = 1000;Q10 = 1000;
Q3 = 1000;Q7 = 1000;Q11 = 1000;
Q4 = 1000;Q8 = 1000;Q12 = 1000;
xs1 = 2000; ys1 = -1000;xs5 = 2000; ys5 = -2000;xs9 = 6000; ys9 = -2000;
xs2 = 4000; ys2 = 2000;xs6 = 3000; ys6 = 1000;xs10 = 7000; ys10 = 1900;
xs3 = 100; ys3 = 1500;xs7 = 1000; ys7 = -1000;xs11 = 3000; ys11 = 2500;
xs4 = 1000; ys4 = -100;xs8 = 500; ys8 = 2500;xs12 = 8000; ys12 = -1000;
xmin = 0; xmax = 10000;
ymin = -4000; ymax = 4000;
H1 = 100;H5 = 100;H9 = 100;
H2 = 100;H6 = 100;H10 = 100;
H3 = 100;H7 = 100;H11 = 100;
H4 = 100;H8 = 100;H12 = 100;
z = 1.5;
gplot = 1;
gcont = 2;
[x,y] = meshgrid(linspace(xmin,xmax,100),linspace(ymin,ymax,100));
e = ones(size(x));
aa = (90-a)*pi/180;
xx1 = (x - xs1)*cos(aa) - (ys1 - y)*sin(aa); yy1 = (y - ys1)*cos(aa) + (xs1 - x)*sin(aa);
xx2 = (x - xs2)*cos(aa) - (ys2 - y)*sin(aa); yy2 = (y - ys2)*cos(aa) + (xs2 - x)*sin(aa);
xx3 = (x - xs3)*cos(aa) - (ys3 - y)*sin(aa); yy3 = (y - ys3)*cos(aa) + (xs3 - x)*sin(aa);
xx4 = (x - xs4)*cos(aa) - (ys4 - y)*sin(aa); yy4 = (y - ys4)*cos(aa) + (xs4 - x)*sin(aa);
xx5 = (x - xs5)*cos(aa) - (ys5 - y)*sin(aa); yy5 = (y - ys5)*cos(aa) + (xs5 - x)*sin(aa);
xx6 = (x - xs6)*cos(aa) - (ys6 - y)*sin(aa); yy6 = (y - ys6)*cos(aa) + (xs6 - x)*sin(aa);
xx7 = (x - xs7)*cos(aa) - (ys7 - y)*sin(aa); yy7 = (y - ys7)*cos(aa) + (xs7 - x)*sin(aa);
xx8 = (x - xs8)*cos(aa) - (ys8 - y)*sin(aa); yy8 = (y - ys8)*cos(aa) + (xs8 - x)*sin(aa);
xx9 = (x - xs9)*cos(aa) - (ys9 - y)*sin(aa); yy9 = (y - ys9)*cos(aa) + (xs9 - x)*sin(aa);
xx10 = (x - xs10)*cos(aa) - (ys10 - y)*sin(aa); yy10 = (y - ys10)*cos(aa) + (xs10 - x)*sin(aa);
xx11 = (x - xs11)*cos(aa) - (ys11 - y)*sin(aa); yy11 = (y - ys11)*cos(aa) + (xs11 - x)*sin(aa);
xx12 = (x - xs12)*cos(aa) - (ys12 - y)*sin(aa); yy12 = (y - ys12)*cos(aa) + (xs12 - x)*sin(aa);
c1 = 1000*Q1*e./(4*pi*(xx1>0).*xx1*sqrt(Dy*Dz)*v).*exp(-v*yy1.*yy1./(4*Dy*(xx1>0.*(exp(-v*(z-H1)*e./(4*Dz*(xx1>0).*xx1)).*(exp(-v*(z-H1)*e))))));
c1(isinf(c1))=0; c1(isnan(c1))=0;
c2 = 1000*Q2*e./(4*pi*(xx2>0).*xx2*sqrt(Dy*Dz)*v).*exp(-v*yy2.*yy2./(4*Dy*(xx2>0.*(exp(-v*(z-H2)*e./(4*Dz*(xx2>0).*xx2)).*(exp(-v*(z-H2)*e))))));
c2(isinf(c2))=0; c2(isnan(c2))=0;
c3 = 1000*Q3*e./(4*pi*(xx3>0).*xx3*sqrt(Dy*Dz)*v).*exp(-v*yy3.*yy3./(4*Dy*(xx3>0.*(exp(-v*(z-H3)*e./(4*Dz*(xx3>0).*xx3)).*(exp(-v*(z-H3)*e))))));
c3(isinf(c3))=0; c3(isnan(c3))=0;
c4 = 1000*Q4*e./(4*pi*(xx4>0).*xx4*sqrt(Dy*Dz)*v).*exp(-v*yy4.*yy1./(4*Dy*(xx4>0.*(exp(-v*(z-H4)*e./(4*Dz*(xx4>0).*xx4)).*(exp(-v*(z-H4)*e))))));
c4(isinf(c4))=0; c4(isnan(c4))=0;
c5 = 1000*Q5*e./(4*pi*(xx5>0).*xx5*sqrt(Dy*Dz)*v).*exp(-v*yy5.*yy5./(4*Dy*(xx5>0.*(exp(-v*(z-H5)*e./(4*Dz*(xx5>0).*xx5)).*(exp(-v*(z-H5)*e))))));
c5(isinf(c5))=0; c5(isnan(c5))=0;
c6 = 1000*Q6*e./(4*pi*(xx6>0).*xx6*sqrt(Dy*Dz)*v).*exp(-v*yy6.*yy6./(4*Dy*(xx6>0.*(exp(-v*(z-H6)*e./(4*Dz*(xx6>0).*xx6)).*(exp(-v*(z-H6)*e))))));
c6(isinf(c6))=0; c6(isnan(c6))=0;
c7 = 1000*Q7*e./(4*pi*(xx7>0).*xx7*sqrt(Dy*Dz)*v).*exp(-v*yy7.*yy7./(4*Dy*(xx7>0.*(exp(-v*(z-H7)*e./(4*Dz*(xx7>0).*xx7)).*(exp(-v*(z-H7)*e))))));
c7(isinf(c7))=0; c7(isnan(c7))=0;
c8 = 1000*Q8*e./(4*pi*(xx8>0).*xx8*sqrt(Dy*Dz)*v).*exp(-v*yy8.*yy8./(4*Dy*(xx8>0.*(exp(-v*(z-H8)*e./(4*Dz*(xx8>0).*xx8)).*(exp(-v*(z-H8)*e))))));
c8(isinf(c8))=0; c8(isnan(c8))=0;
c9 = 1000*Q9*e./(4*pi*(xx9>0).*xx9*sqrt(Dy*Dz)*v).*exp(-v*yy9.*yy9./(4*Dy*(xx9>0.*(exp(-v*(z-H9)*e./(4*Dz*(xx9>0).*xx9)).*(exp(-v*(z-H9)*e))))));
c9(isinf(c9))=0; c9(isnan(c9))=0;
c10 = 1000*Q10*e./(4*pi*(xx10>0).*xx1*sqrt(Dy*Dz)*v).*exp(-v*yy10.*yy10./(4*Dy*(xx10>0.*(exp(-v*(z-H10)*e./(4*Dz*(xx10>0).*xx10)).*(exp(-v*(z-H10)*e))))));
c10(isinf(c1))=0; c1(isnan(c1))=0;
c11 = 1000*Q11*e./(4*pi*(xx11>0).*xx11*sqrt(Dy*Dz)*v).*exp(-v*yy11.*yy11./(4*Dy*(xx11>0.*(exp(-v*(z-H11)*e./(4*Dz*(xx11>0).*xx11)).*(exp(-v*(z-H11)*e))))));
c11(isinf(c11))=0; c11(isnan(c11))=0;
c12 = 1000*Q12*e./(4*pi*(xx12>0).*xx12*sqrt(Dy*Dz)*v).*exp(-v*yy12.*yy12./(4*Dy*(xx12>0.*(exp(-v*(z-H12)*e./(4*Dz*(xx12>0).*xx12)).*(exp(-v*(z-H12)*e))))));
c12(isinf(c12))=0; c12(isnan(c12))=0;
c = c1 + c2 + c3 + c4 + c5 + c6 + c7 + c8 + c9 + c10 + c11 + c12;
if gplot
for i = 1:10:100
plot (c(i,:)); hold on;
end
end
if gcont
figure;
if gcont > 1
contourf (x,y,c); colorbar;
else
contour (x,y,c);
end
end
clc
Please Help me!!
  4 Comments
DGM
DGM on 28 Jul 2021
My connection is too garbage right now to deal with YouTube, but it might help others if you post a link to the video (or tutorial page if it's embedded somewhere).

Sign in to comment.

Answers (1)

Stephen
Stephen on 28 Jul 2021
Edited: Stephen on 28 Jul 2021
You are using MATLAB R2014a, which uses the old graphics system.
That YouTube tutorial uses R2015b, which includes a totally new new graphics system with new features and default settings. The new graphics system (aka "HG2") was introduced in R2014b:
It is expected that these two versions will produce quite different looking graphics. You will have to look at the help for your installed MATLAB to know how to change the plot color and everything else too (and not just follow the tutorial which uses a totally different graphics system with different default colors, nor use the online documentation).
For many years the MATLAB documentation had a few pages explaining these changes, but these have since been removed and are now only viewable via internet archives, e.g.:

Tags

Products


Release

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by