MATLAB: Color area between functions color Hi, I have two functions g = exp(-x.^2./2) and h = x.^2-3.*x+2; there is a region enclosed between them, between x=0 and x=3 I wanna color it using fill how to? =) Best Answer x = -1:.01:4;g = exp(-x.^2./2);h = x.^2-3.*x+2;plot(x, g, 'r', 'LineWidth', 2);hold on;plot(x, h, 'b', 'LineWidth', 2);x=.43:.01:2.08;x2 = [x, fliplr(x)];g = exp(-x.^2./2);h = x.^2-3.*x+2;inBetween = [g, fliplr(h)];fill(x2, inBetween, 'g'); Related SolutionsMATLAB: Shade area under curve between 2 x-axis limits x=0:pi/50:2*pi;y1=x.^2;H1=area(x,y1);hold onidx=x>3&x<4;H=area(x(idx),y1(idx));set(H(1),'FaceColor',[1 0.5 0]);Orclosex=0:pi/50:2*pi;y1=x.^2;%baseval1=20;%baseval2=3;%clf;H1=area(x,y1,'FaceColor',[1 1 1]);hold onidx=x>3&x<4;H=area(x(idx),y1(idx));set(H(1),'FaceColor',[1 0.5 0]); MATLAB: Derivative of a Function If you have the Symbolic Toolbox:>> g = @(x) exp(x^2-2)g = @(x)exp(x^2-2)>> syms x>> diff(g(x))ans =2*x*exp(x^2 - 2) Related QuestionI get an error when I plot itFill the region between two linesHello, have to plot an ineqality and when the solution of the inequality is true matlab has to plot the line at -0.6 instead of 1. what function or code is used in this situationWith what code can I make Matlab do this operation automatically
Best Answer