4.4 matlab三维曲线(plot3函数、fplot3函数) | 您所在的位置:网站首页 › matlab中plot与fplot区别 › 4.4 matlab三维曲线(plot3函数、fplot3函数) |
1、plot3函数 ( 1 ) plot3函数的基本用法 plot3(x,y,z) 其中,参数x、y、z组成一组曲线的坐标。 例1:绘制一条空间折线。 x = [0.2 1.8 2.5]; y = [1.3 2.8 1.1]; z = [0.4 1.2 1.6]; plot3(x,y,z) title('三维曲线','color','r') grid on axis([0,3,1,3,0,2])( 2 ) plot3函数参数的变化形式 plot3(x, y,z) ①参数x、y、z是同型矩阵:则以XYZ对应列元素绘制曲线,曲线条数等于短阵列数。 ②参数x、y、z中有向量,也有矩阵:向量的长度应与矩阵相符,行向量的长度与矩阵的列数相同,列向量的长度与矩阵的行数相同。 例3:在空间不同位置绘制5条正弦曲线。 方法1 列向量 t = linspace(0,2*pi,100); t = t'; x = [t t t t t]; y = [sin(t) sin(t)+1 sin(t)+2 sin(t)+3 sin(t)+4]; z = [t t t t t]; plot3(x,y,z) grid on legend('sin(t)','sin(t)+1','sin(t)+2','sin(t)+3','sin(t)+4','location','north') 方法2 行向量 t = linspace(0,2*pi,100); x = t; y = [sin(t);sin(t)+1;sin(t)+2;sin(t)+3;sin(t)+4]; z = t; plot3(x,y,z) grid on legend('sin(t)','sin(t)+1','sin(t)+2','sin(t)+3','sin(t)+4','location','north')
例4:绘制三条不同长度的正弦曲线。 t1 = 0:0.01:1*pi; t2 = 0:0.01:2*pi; t3 = 0:0.01:3*pi; plot3(t1,sin(t1),t1,t2,sin(t2)+1,t2,t3,sin(t3)+2,t3) legend('sin(t1)','sin(t2)+1','sin(t3)+2','location','north') grid on
|
CopyRight 2018-2019 实验室设备网 版权所有 |