How can I fill the area between a function and the vertical axis x = 0, either for positive or negative values of it?

2 次查看(过去 30 天)

I have several diagrams which plot one function. I want to fill an area between that function (lineal, curve..)and a the vertical axis x = 0. So, how can I fill the area, either for positive or negative values of it?

The function is a piecewise function. The code of one case is:

 y_B1 = 0:0.01:h_poste;
        Mz_B1 = -((y_B1<=h_hc).*(R_Mz_v1_B+R_Vx_B1.*y_B1+((1/2).*y_B1.*y_B1*(Qwstr1/h_poste)*(1/3).*y_B1))+((y_B1>h_hc)&(y_B1<=h_CdPa)).*(R_Mz_v1_B+R_Vx_B1.*y_B1+((1/2).*y_B1.*y_B1*(Qwstr1/h_poste)*(1/3).*y_B1)+M_hc+(Esf_rad_hc+Qwc(1)).*(y_B1-(h_hc+ht)))+((y_B1>h_CdPa)&(y_B1<=cdg_mensula_y)).*(R_Mz_v1_B+R_Vx_B1.*y_B1+((1/2).*y_B1.*y_B1*(Qwstr1/h_poste)*(1/3).*y_B1)+M_hc+(Esf_rad_hc+Qwc(1)).*(y_B1-(h_hc+ht))+M_CdPa+(Esf_rad_CdPa_B+Qwc(3)).*(y_B1-(h_CdPa)))+((y_B1>cdg_mensula_y)&(y_B1<=h_sust)).*(R_Mz_v1_B+R_Vx_B1.*y_B1+((1/2).*y_B1*(Qwstr1/h_poste)*(1/3).*y_B1)+M_hc+(Esf_rad_hc+Qwc(1)).*(y_B1-(h_hc+ht))+M_CdPa+(Esf_rad_CdPa_B+Qwc(3)).*(y_B1-(h_CdPa))+M_mensula)+((y_B1>h_sust)&(y_B1<=h_Feed)).*(R_Mz_v1_B+R_Vx_B1.*y_B1+((1/2).*y_B1.*y_B1*(Qwstr1/h_poste)*(1/3).*y_B1)+M_hc+(Esf_rad_hc+Qwc(1)).*(y_B1-(h_hc+ht))+M_CdPa+(Esf_rad_CdPa_B+Qwc(3)).*(y_B1-(h_CdPa))+M_mensula+M_sust+(Esf_rad_sust+Qwc(2)).*(y_B1-(h_sust+ht)))+((y_B1>h_Feed)&(y_B1<=h_poste)).*(R_Mz_v1_B+R_Vx_B1.*y_B1+((1/2).*y_B1.*y_B1*(Qwstr1/h_poste)*(1/3).*y_B1)+M_hc+(Esf_rad_hc+Qwc(1)).*(y_B1-(h_hc+ht))+M_CdPa+(Esf_rad_CdPa_B+Qwc(3)).*(y_B1-(h_CdPa))+M_mensula+M_sust+(Esf_rad_sust+Qwc(2)).*(y_B1-(h_sust+ht))+M_Feed+(Esf_rad_Feed_B+Qwc(4)).*(y_B1-(h_Feed))));
        figure
        ley_Mz_B1 = plot(Mz_B1,y_B1);grid;
        title('CASO DE CARGA B (Viento 1).Ley de esfuerzos flectores')
        xlabel('Momento flector Mz (N·m)');
        ylabel('Altura (m)');

where Mz_B1 is the function represented and y_B1 is the vector of independent values.

NOTE: the black area has been made using Paint.

采纳的回答

Mike Garrity
Mike Garrity 2016-3-17
This post I did on the MATLAB Graphics blog might give you some ideas on how to do this.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Polygons 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by