当前位置:首页>正文

关于matlab中nbsp;patch的用法 MATLAB中plot函数用法

2023-07-07 09:40:48 互联网 未知

关于matlab中nbsppatch的用法

PATCHnbspCreatenbsppatch.nbspPATCH(X,Y,C)nbspaddsnbspthenbsp“patch“nbspornbspfillednbsp2-DnbsppolygonnbspdefinednbspbynbspvectorsnbspXnbspandnbspYnbsptonbspthenbspcurrentnbspaxes.nbspIfnbspXnbspandnbspYnbsparenbspmatricesnbspofnbspthenbspsamenbspsize,nbsponenbsppolygonnbsp(“face“)nbsppernbspcolumnnbspisnbspadded.nbspCnbspspecifiesnbspthenbspcolornbspofnbspthenbspface(s)nbsp(“flat“nbspcoloring),nbspornbspthenbspverticesnbsp(“interpolated“nbspcoloring),nbspfornbspwhichnbspbilinearnbspinterpolationnbspisnbspusednbsptonbspdeterminenbspthenbspinteriornbspcolornbspofnbspthenbsppolygon.nbspFornbspbothnbspvectornbspornbspmatrixnbspXnbspandnbspY,nbspifnbspCnbspisnbspanbspstring,nbspeachnbspfacenbspisnbspfillednbspwithnbsp‘color‘.nbsp‘color‘nbspcannbspbenbsp‘r‘,‘g‘,‘b‘,‘c‘,‘m‘,‘y‘,nbsp‘w‘,nbspornbsp‘k‘.nbspIfnbspCnbspisnbspanbspscalarnbspitnbspspecifiesnbspthenbspcolornbspofnbspthenbspface(s)nbspbynbspindexingnbspintonbspthenbspcolormap.nbspAnbsp1x3nbspvectornbspCnbspisnbspalwaysnbspassumednbsptonbspbenbspannbspRGBnbsptripletnbspspecifyingnbspanbspcolornbspdirectly.nbspFornbspvectornbspXnbspandnbspY,nbspifnbspCnbspisnbspanbspvectornbspofnbspthenbspsamenbsplength,nbspitnbspspecifiesnbspthenbspcolornbspofnbspeachnbspvertexnbspasnbspindicesnbspintonbspthenbspcolormapnbspandnbspbilinearnbspinterpolationnbspisnbspusednbsptonbspdeterminenbspthenbspinteriornbspcolornbspofnbspthenbsppolygonnbsp(“interpolated“nbspshading).nbspWhennbspXnbspandnbspYnbsparenbspmatrices,nbspifnbspCnbspisnbspanbsp1xn,nbspwherenbspnnbspisnbspthenbspnumbernbspofnbspcolumnsnbspinnbspXnbspandnbspY,nbspthennbspeachnbspfacenbspj=1:nnbspisnbspflatnbspcolorednbspbynbspthenbspcolormapnbspindexnbspC(j).nbspNotenbspthenbspspecialnbspcasenbspofnbspanbsp1x3nbspCnbspisnbspalwaysnbspassumednbsptonbspbenbspannbspRGBnbsptripletnbspColorSpecnbspandnbspspecifiesnbspthenbspsamenbspflatnbspcolornbspfornbspeachnbspface.nbspIfnbspCnbspisnbspanbspmatrixnbspthenbspsamenbspsizenbspasnbspXnbspandnbspY,nbspthennbspitnbspspecifiesnbspthenbspcolorsnbspatnbspthenbspverticesnbspasnbspcolormapnbspindicesnbspandnbspbilinearnbspinterpolationnbspisnbspusednbsptonbspcolornbspthenbspfaces.nbspIfnbspCnbspisnbsp1xnx3,nbspwherenbspnnbspisnbspthenbspnumbernbspofnbspcolumnsnbspofnbspXnbspandnbspY,nbspthennbspeachnbspfacenbspjnbspisnbspflatnbspcolorednbspbynbspthenbspRGBnbsptripletnbspC(1,j,:).nbspIfnbspCnbspisnbspmxnx3,nbspwherenbspXnbspandnbspYnbsparenbspmxn,nbspthennbspeachnbspvertexnbsp(X(i,j),Y(i,j))nbspisnbspcolorednbspbynbspthenbspRGBnbsptripletnbspC(i,j,:)nbspandnbspthenbspfacenbspisnbspcolorednbspusingnbspinterpolation.nbspPATCH(X,Y,Z,C)nbspcreatesnbspanbsppatchnbspinnbsp3-Dnbspcoordinates.nbspZnbspmustnbspbenbspthenbspsamenbspsizenbspasnbspXnbspandnbspY.nbspPATCHnbspreturnsnbspanbsphandle

MATLAB中plot函数用法

f=sin(x).*(1 x).*log(1 x) 中的x是矩阵 所以 sin(x)也是矩阵(你可以看看sin(x)的大小就知道了)
要加.才能实现矩阵对应的元素相乘 如果不加是两个矩阵相乘

matlab 画图 三元函数

首先考虑了用隐函数生成图像,函数如下

>> ezsurf((abs(x) abs(y)-1).*((abs(x) abs(y))<1),[-1 1 -1 1 ])

>> hold on

>> ezsurf(-(abs(x) abs(y)-1).*((abs(x) abs(y))<1),[-1 1 -1 1 ])

>> axis equal

>> view(-30,10)

>> 

图片如图所示,不过存在一个没法解决的问题,就是显示范围,这个隐函数在

[-1 1 -1 1]整个范围内都能算出值,虽然在我把xy超出范围的值都置0了,不过0也能画出来。

想了半天也想不出来怎么把筛选矩阵abs(x) abs(y))<1的0都变成NaN,因为不能直接一个语句就表达出来。

画这个东西还有个方法,就是用patch,这个函数是能画出一系列的多边形,你可以直接用这个函数画8个三角形出来。 

用patch的方法我写了一个m函数,很简单

function point

p=[1 0 00 -1 0-1 0 00 1 00 0 1 0 0 -1]

v=[1 2 61 4 62 3 63 4 61 2 51 4 52 3 53 4 5]

clf

patch(faces,v,vertices,p,facevertexcdata,jet(8),facecolor,flat)

axis equal

axis([-1 1 -1 1 -1 1])

grid on

view(-20,10)

matlab 函数画图拼接

首先你把两个自变量的名字弄成不一样的。
另外值的名称和函数名称用一样的,这个做法不好。
然后代码非常简单。。。
关键在于使用 hold on 和 hold off
t1 = 0:0.01:10
y1_val = y1(t)
t2 = 10:0.01:20
y2_val = y2(t)
figure_1 = figure
f1 = plot(t1, y1)
hold on
f2 = plot(t2, y2)
hold off

随便看看