你好,你的问题好像没太描述清楚。
分段函数绘图实际很简单,我给你举个例子吧。
分段函数如下:
对该函数绘图,首先应该利用matlab建一个函数ff(x),如下:
function Y = ff(X)
if X<0;
Y=sin(X);
elseif (X>=0 && X<10);
Y=X.^2*cos(X)/100;
else
Y=sin(X).*X;
end
end
matlab中二维绘图函数很多,但我个人认为分段函数采用ezplot较为简单。绘制方法如下:
ezplot(@(x,y)ff(x)-y)
colormap([0 0 1]) %%设置直线颜色为蓝色。
绘制结果如下:
ezplot简介(具体看帮助文档 doc ezplot)
Syntax
ezplot(fun)
ezplot(fun,[xmin,xmax])
ezplot(fun2)
ezplot(fun2,[xymin,xymax])
ezplot(fun2,[xmin,xmax,ymin,ymax])
ezplot(funx,funy)
ezplot(funx,funy,[tmin,tmax])
ezplot(...,figure_handle)
ezplot(axes_handle,...)
h = ezplot(...)
Description
ezplot(fun) plots the expression fun(x) over the default domain -2π < x < 2π, where fun(x) is an explicit function of only x.
fun can be a function handle or a string.
ezplot(fun,[xmin,xmax]) plots fun(x) over the domain: xmin < x < xmax.
For an implicit function, fun2(x,y):
ezplot(fun2) plots fun2(x,y) = 0 over the default domain -2π < x < 2π, -2π < y < 2π.
ezplot(fun2,[xymin,xymax]) plots fun2(x,y) = 0 over xymin < x < xymax and xymin < y < xymax.
ezplot(fun2,[xmin,xmax,ymin,ymax]) plots fun2(x,y) = 0 over xmin < x < xmax and ymin < y < ymax.
ezplot(funx,funy) plots the parametrically defined planar curve funx(t) and funy(t) over the default domain 0 < t < 2π.
ezplot(funx,funy,[tmin,tmax]) plots funx(t) and funy(t) over tmin < t < tmax.
ezplot(...,figure_handle) plots the given function over the specified domain in the figure window identified by the handle figure.
ezplot(axes_handle,...) plots into the axes with handle axes_handle instead of the current axes (gca).
h = ezplot(...) returns the handle to all the plot objects in h.
这直接用直线连接,没有插值的话,直接把x坐标输入到x变量下,x=[0:1:23];
把y坐标输入到y变量下,y=[8,7.42,7.85,7.5,6.8,6.8,8.6,10.4,12.41,14,14.46,14.8,12.9,12.5,12.78,12.7,12.1,13.5,14.2,13.8,13.1,12.7,9.6,8.3];
然后plot(x,y)就行。
代码如下:
>>x=0:23;
>>y=[8,7.42,7.85,7.5,6.8,6.8,8.6,10.4,12.41,14,14.46,14.8,12.9,12.5,12.78,12.7,12.1,13.5,14.2,13.8,13.1,12.7,9.6,8.3];
>>plot(x,y);
不用分段函数
x=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23];
y=[8,7.42,7.85,7.5,6.8,6.8,8.6,10.4,12.41,14,14.46,14.8,12.9,12.5,12.78,12.7,12.1,13.5,14.2,13.8,13.1,12.7,9.6,8.3];
plot(x,y)
xlabel('时间(t)')
ylabel('负载(MKW)')
问题都没描述清楚怎么帮你。。。