How to change plot marks with each step
Afficher commentaires plus anciens
Hello everyone,
So I have the following code. What I want is to plot the same colors at marks under the same "i" value. So for example if i =200 then the marks are blue, if i= 300 all marks are red etc. Does anybody know how to do that? I tried several things but didn't work.
R = 83.1446;
b = 58;
for i = 200:100:1000
T = i + 273.15;
d = (9380 - (8.53.*T))
c = (28.31 + (0.10721.*T))
e = (-368654 + (715.9.*T))
for v = 150:1:250;
y = b./(4*v);
a = c + d./v + e./(v.^2);
P = (R*T.*(1 + y + y.^2 - y.^3))./(v.*(1-y).^3)- a./(sqrt(T)*v.*(v+b));
Z = (1+y+y.^2-y.^3)./((1-y).^3) - a./(R*T^1.5.*(v+b));
lnfi =(8*y-9*y.^2+3*y.^3)
fi=exp(lnfi);
f=abs(fi.*P);
plot(P,f,'.')
drawnow
hold on
end
end
hold off
5 commentaires
In plot(P,f,'.') there's no reference to color and so you'll just get default. Make up a color list for each i and use it:
If you use plot, each plot call is a new line handle; and a line can only have one color. You could simplify that process by rearranging to save the values for each T and plot all at one time with the chosen color. That could also eliminate one loop by using the vectorized form of the equations you've written as
v=150:250;
y = b./(4*v);
a = c + d./v + e./(v.^2);
P = (R*T.*(1 + y + y.^2 - y.^3))./(v.*(1-y).^3)- a./(sqrt(T)*v.*(v+b));
Z = (1+y+y.^2-y.^3)./((1-y).^3) - a./(R*T^1.5.*(v+b));
lnfi =(8*y-9*y.^2+3*y.^3)
fi=exp(lnfi);
f=abs(fi.*P);
hL(i)=plot(P,f,'.',clr(i,:));
Where clr(i,:) is the defined color triplet for ith T you'll have defined before beginning the loop.
Dimitris Moutzouris
le 3 Avr 2020
dpb
le 3 Avr 2020
Because you buried data in the for...end loop on i and both Ameer and I fell into the trap...
Instead of
for i = 200:100:1000
T = i + 273.15;
...
use something like
T0=[200:100:1000]; % put the temperature data out of code so easily changed
for i = 1:numel(T0)
T = T0(i) + 273.15; % do the units conversion
...
Would be even better to vectorize, but above is the least editing of existing code to make data independent.
Dimitris Moutzouris
le 3 Avr 2020
Ameer Hamza
le 3 Avr 2020
dbp, that correct. I didn't notice that at first, too. :D
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Annotations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!