2016-12-13 9 views
2

Ich bin auf diesem Code arbeiten Liner Stromverbrauch Ergebnis zu erhalten:Matlab Plots Bereich Färbung

P_out = 0:100; 
Po= 130 ;   
dP= 4.7 ;   
N_TRX=6; 
P_max= 20; 
p_sleep= 75; 

if 0< P_out <= P_max 
    P = N_TRX*Po+N_TRX*dP*P_out; 
else 
    P=N_TRX* p_sleep; 
end 
%%%%% 
Po= 130 ;   
dP= 2.8 ;   
N_TRX=6; 
P_max= 40; 

if 0< P_out <= P_max 
    P1= N_TRX*Po+N_TRX*dP*P_out; 
else 
    P1=N_TRX* p_sleep; 
end 
%%%%% 
Po= 130 ;   
dP= 5.9 ;   
N_TRX=2; 
P_max= 20; 

if 0< P_out <= P_max 
    P2= N_TRX*(Po+dP*P_out); 
else 
    P_in2=N_TRX* p_sleep; 
end 
%%%%% 
Po= 110 ;   
dP= 4.2;   
N_TRX=6; 
P_max= 20; 

if 0< P_out <= P_max_macro 
    P3= N_TRX*Po+N_TRX*dP*P_out; 
else 
    P3=N_TRX* p_sleep; 
end 

figure, plot(P_out,P,'b'); hold on, plot(P_out,P1,'g'); hold on,  plot(P_out,P2,'r'); hold on,plot (P_out,P3,'y'),hold off 

Die Handlung ist hier:

the plot is here

und ich möchte den Bereich zwischen füllen die Linien mit Farben, um 4 Bereiche mit ihrer Linienfarbe zu färben.

Antwort

1

Dies ist eine Möglichkeit, dies mit der area Funktion zu tun:

h = area(P_out,[P2;P1-P2;P3-P1;P-P3].'); 
h(1).FaceColor = 'r'; 
h(2).FaceColor = 'g'; 
h(3).FaceColor = 'y'; 
h(4).FaceColor = 'b'; 

Welche Sie dies geben:

fillArea4

Sie auch einige schönere Farben und Transparenz verwenden können:

ax = axes; 
col = mat2cell(lines(4),ones(4,1),3); 
hold on 
h(1) = area(ax,P_out,P); 
h(4) = area(ax,P_out,P3); 
h(2) = area(ax,P_out,P1); 
h(3) = area(ax,P_out,P2); 
set(h,{'FaceColor'},col) 
set(h,'FaceAlpha',0.6) 
hold off 

, um dies zu erhalten: