How to make real and imaginary plot of the graph same color

3 visualizzazioni (ultimi 30 giorni)
In my code I have a for loop and with every iteration i tell matlab to draw real part of the curve as a solid line and imaginary part of the curve as a dashed line. What I would like to have is for each iteration the real and imaginary part of the same curve to have the same color, could anyone help?
clear all
%%
v=0:1e+9:1e+12; %Frequency (Hertz)
t0=0; %Minimum Temperature (Celsius)
tstep=20; %Temperature Step
tmax=100; %Maximum Temperature
%%
for t=t0:tstep:tmax
t=t';
tc=133.1383;
a=[79.23882 3.815866 1.634967];
b=[0.004300598 0.01117295 0.006841548];
c=[1.382264e-13 3.510354e-16 6.30035e-15];
d=[652.7648 1249.533 405.5169];
delta=a.*exp(-b.*t);
tau=c.*exp(d./(t+tc));
es=87.9144 - 0.404399.*t + 9.58726*10^(-4).*t.^2 -1.32802*10^(-6).*t.^3;
p0=0.8379692;
p1=-0.006118594;
p2=-0.000012936798;
p3=4235901000000;
p4=-14260880000;
p5=273815700;
p6=-1246943;
p7=9.618642e-14;
p8=1.795786e-16;
p9=-9.310017e-18;
p10=1.655473e-19;
p11=0.6165532;
p12=0.007238532;
p13=-0.00009523366;
p14=15983170000000;
p15=-74413570000;
p16=497448000;
p17=2.882476e-14;
p18=-3.142118e-16;
p19=3.528051e-18;
delta4=p0+p1.*t+p2.*t.^2;
delta5=p11+p12.*t+p13.*t.^2;
tau4=p7+p8.*t+p9.*t.^2+p10.*t.^3;
tau5=p17+p18.*t+p19.*t.^2;
func4=p3+p4.*t+p5.*t.^2+p6.*t.^3;
func5=p14+p15.*t+p16.*t.^2;
e_real=es-(2*pi.*v).^2.*(...
tau(1).^2*delta(1)./(1+(2*pi.*v.*tau(1)).^2)+...
tau(2).^2*delta(2)./(1+(2*pi.*v.*tau(2)).^2)+...
tau(3).^2*delta(3)./(1+(2*pi.*v.*tau(3)).^2))...
-(2*pi.*tau4).^2.*0.5.*delta4.*(...
v.*(func4+v)./(1+(2*pi.*tau4.*(func4+v)).^2)-...
v.*(func4-v)./(1+(2*pi.*tau4.*(func4-v)).^2))...
-(2*pi.*tau5).^2.*0.5.*delta5.*(...
v.*(func5+v)./(1+(2*pi.*tau5.*(func5+v)).^2)-...
v.*(func5-v)./(1+(2*pi.*tau5.*(func5-v)).^2));
e_imag=2.*pi.*v.*(...
tau(1).*delta(1)./(1+(2.*pi.*v.*tau(1)).^2)+...
tau(2).*delta(2)./(1+(2*pi.*v.*tau(2)).^2)+...
tau(3).*delta(3)./(1+(2*pi.*v.*tau(3)).^2))+...
pi.*v.*tau4.*delta4.*(...
1./(1+(2*pi.*tau4.*(func4+v)).^2)+...
1./(1+(2*pi.*tau4.*(func4-v)).^2))+...
pi.*v.*tau5.*delta5.*(...
1./(1+(2*pi.*tau5.*(func5+v)).^2)+...
1./(1+(2*pi.*tau5.*(func5-v)).^2));
e=e_real+1j.*e_imag;
semilogx(imag(e),'--')
set(gca,'FontSize',20);
set(gca,'Color','k');
title('Relative Permittivity of Water vs Frequency & Water Temperature', 'Fontsize', 40);
xlabel('Frequency (Hz)','Fontsize', 40) ;
ylabel('Relative Permittivity', 'Fontsize', 40) ;
hold on
semilogx(real(e))
end

Risposta accettata

Giuseppe Inghilterra
Giuseppe Inghilterra il 19 Feb 2020
Hi,
a fast and easy solution could be generate a triplette of RGB values randomly at each iteration and you use it as color for both plots, as you can see in the following code:
RGB = rand(3,1);
semilogx(imag(e),'--','Color',RGB)
set(gca,'FontSize',20);
set(gca,'Color','k');
title('Relative Permittivity of Water vs Frequency & Water Temperature', 'Fontsize', 40);
xlabel('Frequency (Hz)','Fontsize', 40) ;
ylabel('Relative Permittivity', 'Fontsize', 40) ;
hold on
semilogx(real(e),'Color',RGB)
I have defined RGB vector that I use as color property for both plots. In this way both plots have the same color.
An alternative you could define a matrix of RGB values in order to control which color you want at each iteration for both plots.
Hope this helps.

Più risposte (0)

Categorie

Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange

Tag

Prodotti


Release

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by