mdsk.net
当前位置:首页 >> MATLAB中如何对一条曲线和X轴之间的区域进行颜色的... >>

MATLAB中如何对一条曲线和X轴之间的区域进行颜色的...

这个没有一次性的办法,只能用area分段拼凑出来了: close all x = 0:0.1:pi; y = sin(x); area(x,y,'FaceColor','r'); hold on x = pi:0.1:2*pi; y = sin(x); area(x,y,'FaceColor','g'); x = 2*pi:0.1:3*pi; y = sin(x); area(x,y,'FaceColor'...

ezplot('x^2-5*x-9',[-4 8 -20 20]); hold on; x = solve('x^2-5*x-9'); x1 = double(x(1)); x2 = double(x(2)); xx = x2:.1:x1; yy = xx.^2-5*xx-9; patch(xx,yy,xx); plot(-4:8,zeros(1,13),'k-'); plot(zeros(1,41),-20:20,'k-'); hold off;

x=linspace(0,10); y1=sin(x)-1; y2=sin(x); fill([x,fliplr(x)],[y1,fliplr(y2)],'r')

这个没有一次性的办法,只能用area分段拼凑出来了: close all x = 0:0.1:pi; y = sin(x); area(x,y,'FaceColor','r'); hold on x = pi:0.1:2*pi; y = sin(x); area(x,y,'FaceColor','g'); x = 2*pi:0.1:3*pi; y = sin(x); area(x,y,'FaceColor'...

可以用patch命令,很简单的,把这几条线作为边界参数即可。具体语句写法见help patch。

clear all;clc; t=linspace(0,pi,300); y1=sin(t(1:50)); y2=sin(t(50:end)); plot(t(1:50),y1,'r');hold on; plot(t(50:end),y2,'b');

t=-2*pi:pi/20:0; y=sin(t); plot(t,y) hold on t=0:pi/20:2*pi; y=sin(t); plotyy(t,y,t,y,'plot','stem'); xlabel('X Axis'); ylabel('Y Axis'); hold off

matlab里面用plot画的图每条曲线的线型,颜色都可以变,例如plot(x,y,'r','*');代表红色和*线型。 至于要达到你说的效果估计得分段画图,就跟曲线分段表示一样

N = 50; % 数据点的点数x = linspace(0,pi,N)'; % x坐标y = sin(x); % y坐标Q = zeros(N,1);for i = 2:N Q(i) = trapz(x(1:i),y(1:i)); % y值与x轴所包围的面积endQ % 曲线与x轴所包围的面积plot(x,y,'-.',x,Q,'-')

t=0:0.01:2*pi; y=sin(t); y2=y+2; plot(t,y,t,y2,'r') hold on % 如果t的维数较小,可以加细 n=length(t); for i=1:n x1=[t(i),t(i)]; y1=[y(i),y2(i)]; plot(x1,y1,'k'); end

网站首页 | 网站地图
All rights reserved Powered by www.mdsk.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com