matlab 三维直线怎么画
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了matlab 三维直线怎么画相关的知识,希望对你有一定的参考价值。
matlab三维直线画法:可以用plot3函数来画。它与plot函数用法十分相似,其调用格式为:
plot3(x1,y1,z1,选项1,x2,y2,z2,选项2,…,xn,yn,zn,选项n)
例如:
t=0:pi/100:20*pi;
x=sin(t);
y=cos(t);
z=t.*sin(t).*cos(t);
plot3(x,y,z);
title(\'Line in 3-D Space\');
xlabel(\'X\');ylabel(\'Y\');zlabel(\'Z\')
matlab简介:
MATLAB是美国MathWorks公司出品的商业数学软件,用于算法开发、数据可视化、数据分析以及数值计算的高级技术计算语言和交互式环境,主要包括MATLAB和Simulink两大部分。
MATLAB是matrix&laboratory两个词的组合,意为矩阵工厂(矩阵实验室)。是由美国mathworks公司发布的主要面对科学计算、可视化以及交互式程序设计的高科技计算环境。它将数值分析、矩阵计算、科学数据可视化以及非线性动态系统的建模和仿真等诸多强大功能集成在一个易于使用的视窗环境中,为科学研究、工程设计以及必须进行有效数值计算的众多科学领域提供了一种全面的解决方案,并在很大程度上摆脱了传统非交互式程序设计语言(如C、Fortran)的编辑模式,代表了当今国际科学计算软件的先进水平。 参考技术A plot3(x,y,z);
x,y,z都是数组!追问
能不能详细点 举个例子...
追答clc;
clear
n=2;
t=linspace(1,10*pi,n)
x=sin(t);
y=cos(t);
z=t
plot3(x,y,z)
matlab画三维空间劣弧,matlab 三维空间画图总结
matlab 三维画图总结
1.画函数的三维图,如:Z(X,Y)=2*X.*exp(-X.^2-Y.^2)+1;
close all;
[X,Y]=meshgrid(-2:0.5:2,-2:0.5:2);%生成坐标轴
Z=2*X.*exp(-X.^2-Y.^2)+1;%Z是X,Y的函数
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
num=0;
num=num+1;
subplot(2,3,num);
plot3(X,Y,Z);
axis([-3 3 -3 3 0 2]);%限定显示的范围
xlabel('x轴');%x轴坐标
ylabel('y轴');%y轴坐标
zlabel('z轴');%z轴坐标
title('http://blog.csdn.net/nuptboyzhb/ figure(1)');%标题
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
num=num+1;
subplot(2,3,num);
mesh(X,Y,Z);
axis([-3 3 -3 3 0 2]);%限定显示的范围
xlabel('x轴');%x轴坐标
ylabel('y轴');%y轴坐标
zlabel('z轴');%z轴坐标
title('http://blog.csdn.net/nuptboyzhb/ figure(2)');%标题
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
num=num+1;
subplot(2,3,num);
meshc(X,Y,Z);
axis([-3 3 -3 3 0 2]);%限定显示的范围
xlabel('x轴');%x轴坐标
ylabel('y轴');%y轴坐标
zlabel('z轴');%z轴坐标
title('http://blog.csdn.net/nuptboyzhb/ figure(3)');%标题
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
num=num+1;
subplot(2,3,num);
surf(X,Y,Z);
axis([-3 3 -3 3 0 2]);%限定显示的范围
xlabel('x轴');%x轴坐标
ylabel('y轴');%y轴坐标
zlabel('z轴');%z轴坐标
title('http://blog.csdn.net/nuptboyzhb/ figure(4)');%标题
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
num=num+1;
subplot(2,3,num);
meshz(X,Y,Z);
axis([-3 3 -3 3 0 2]);%限定显示的范围
xlabel('x轴');%x轴坐标
ylabel('y轴');%y轴坐标
zlabel('z轴');%z轴坐标
title('http://blog.csdn.net/nuptboyzhb/ figure(5)');%标题
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
num=num+1;
subplot(2,3,num);
surf(X,Y,Z);
hold on;
stem3(X,Y,Z,'r');%画竖线
axis([-3 3 -3 3 0 2]);%限定显示的范围
xlabel('x轴');%x轴坐标
ylabel('y轴');%y轴坐标
zlabel('z轴');%z轴坐标
title('http://blog.csdn.net/nuptboyzhb/ figure(6)');%标题
2.画矩阵的三维图
clc;
clear all;
close all;
X=[0 1 2 3 4 5 6 7 8 9];
Y=[0 1 2 3 4 5 6 7 8 9];
for i=1:1:length(X)
for j=1:1:length(Y)
Z(i,j)=mod(i*j*rand(1),9);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
num=0;
num=num+1;
subplot(2,3,num);
plot3(X,Y,Z);
axis([0 9 0 9 0 9]);%限定显示的范围
xlabel('x轴');%x轴坐标
ylabel('y轴');%y轴坐标
zlabel('z轴');%z轴坐标
title('http://blog.csdn.net/nuptboyzhb/ figure(1)');%标题
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
num=num+1;
subplot(2,3,num);
mesh(X,Y,Z);
axis([0 9 0 9 0 9]);%限定显示的范围
xlabel('x轴');%x轴坐标
ylabel('y轴');%y轴坐标
zlabel('z轴');%z轴坐标
title('http://blog.csdn.net/nuptboyzhb/ figure(2)');%标题
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
num=num+1;
subplot(2,3,num);
meshc(X,Y,Z);
axis([0 9 0 9 0 9]);%限定显示的范围
xlabel('x轴');%x轴坐标
ylabel('y轴');%y轴坐标
zlabel('z轴');%z轴坐标
title('http://blog.csdn.net/nuptboyzhb/ figure(3)');%标题
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
num=num+1;
subplot(2,3,num);
surf(X,Y,Z);
axis([0 9 0 9 0 9]);%限定显示的范围
xlabel('x轴');%x轴坐标
ylabel('y轴');%y轴坐标
zlabel('z轴');%z轴坐标
title('http://blog.csdn.net/nuptboyzhb/ figure(4)');%标题
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
num=num+1;
subplot(2,3,num);
meshz(X,Y,Z);
axis([0 9 0 9 0 9]);%限定显示的范围
xlabel('x轴');%x轴坐标
ylabel('y轴');%y轴坐标
zlabel('z轴');%z轴坐标
title('http://blog.csdn.net/nuptboyzhb/ figure(5)');%标题
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
num=num+1;
subplot(2,3,num);
surf(X,Y,Z);
hold on;
stem3(X,Y,Z,'r');%画竖线
axis([0 9 0 9 0 9]);%限定显示的范围
xlabel('x轴');%x轴坐标
ylabel('y轴');%y轴坐标
zlabel('z轴');%z轴坐标
title('http://blog.csdn.net/nuptboyzhb/ figure(6)');%标题
3.画矩阵的颜色深度图
我自己编写的一个函数:graycolor.m
%filename:graycolor.m
%郑海波 2013-01-31
%http://blog.csdn.net/nuptboyzhb/
%原理:灰度图像的伪彩色处理
%值越大,显示的颜色越蓝,越小,显示的颜色越红!
%参数:newbuf必须使二维数组或矩阵
function graycolor(newbuf);
min_n=min(min(newbuf));
max_n=max(max(newbuf));
newbuf=newbuf./(max_n-min_n)*255;
[M N]=size(newbuf);
for i=1:1:M
for j=1:1:N
R(i,j)=GrayColorR(newbuf(i,j));
G(i,j)=GrayColorG(newbuf(i,j));
B(i,j)=GrayColorB(newbuf(i,j));
end
end
img(1:1:M,1:1:N,1)=R(1:M,1:N);
img(1:1:M,1:1:N,2)=G(1:M,1:N);
img(1:1:M,1:1:N,3)=B(1:M,1:N);
imshow(uint8(img));
function r=GrayColorR(gray)
r=0;
if gray>=170
r=255;
end
if gray>=128&&gray<=170
r=255/42*(gray-128);
end
return;
function g=GrayColorG(gray)
g=0;
if gray>=84&&gray<=170
g=255;
end
if gray<=84
g=255/84*gray;
end
if gray>=170&&gray<=255
g=255/85*(255-gray);
end
return;
function b=GrayColorB(gray)
b=0;
if gray<=84
b=255;
end
if gray>=84&&gray<=128
b=255/44*(128-gray);
end
return;
函数的调用:
[X,Y]=meshgrid(-2:0.01:2,-2:0.01:2);%生成坐标轴
Z=2*X.*exp(-X.^2-Y.^2)+1;%Z是X,Y的函数
graycolor(Z);
title('http://blog.csdn.net/nuptboyzhb/');%标题
另外,在\\matlab2009a\\toolbox\\matlab\\demos\\graf3d.m中文件,有更加详细的介绍。界面如下:
以上是关于matlab 三维直线怎么画的主要内容,如果未能解决你的问题,请参考以下文章
MATLAB中用mesh函数画出三维图后,怎么添加一个Z=0的平面?