在notebook里使用matlab作图

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

1安装word 安装matlab
2.在matalb的commond窗口输入 notebook –setup 然后按回车
3.输入notebook 即可启动word
4,输入matlab命令如 pi 然后选中(单行可以不选中)后按下 alt+D 组合键,变绿色,如下所示
5.再按下 ctrl+Enter键,执行,出现蓝色结果或者图片。

如下所示
以下介绍几个matlab基本的操作命令,然后重点写了几个绘图命令(绿色为输入,蓝色为输出)pi
ans =
3.1416
vpa(pi,100)
ans =
3.149323846264338327953993752117068
syms x f;f=@(x)100*(x(2)-x(1)^2)+(1-x(1))^2
f =
@(x)100*(x(2)-x(1)^2)+(1-x(1))^2
x=[1 2],f(x)
x =
1 2
ans =
100
y=[2 1];f(y)
ans =
-299
x=linspace(0,2*pi,30);
y=sin(x);
z=cos(x);
plot(x,y,'r',x,z,'go')
ezplot('sin(x)',[0,5*pi])
ezplot('cos(t)^3','sin(t)^3',[0,2*pi])
ezplot('exp(x)+sin(x*y)',[-2,0.5,0,2])
myfun2=@(x) exp(2.*x)+sin(3.*x.^ 2) myfun2 =
@(x)exp(2.*x)+sin(3.*x.^2)
plot(-1:0.01:2,myfun2(-1:0.01:2))
fplot(myfun2,[-1,2]);
fplot('tanh',[-2,2])
sn = @(x) sin(1./x);
fplot(sn,[0.01,0.1])
fplot('[tanh(x),sin(x),cos(x)]',2*pi*[-1 1])
x=logspace(-1,2); loglog(x,exp(x),'-s') grid on
t=0:pi/50:10*pi;
plot3(sin(t),cos(t),t) rotate3d
x=-3:0.1:3;
y=1:0.1:5;
[X,Y]=meshgrid(x,y); Z=(X+Y).^2;
surf(X,Y,Z)
shading flat
x=-3:0.1:3; y=1:0.1:5; [X,Y]=meshgrid(x,y); Z=(X+Y).^2;
mesh(X,Y,Z)
[X,Y]=meshgrid(-3:.125:3); Z=peaks(X,Y);
meshz(X,Y,Z)
x=linspace(0,2*pi,30);
y=sin(x);
plot(x,y)
xlabel('自变量X')
ylabel('函数Y')
title('示意图')
grid on
x=linspace(0,2*pi,30);
y=sin(x);
z=cos(x);
plot(x,y,x,z)
gtext('sin(x)');gtext('cos(x)')
x=linspace(0,2*pi,30);
y=sin(x);
z=cos(x);
plot(x,z,':')
hold on
plot(x,y)
x=linspace(0,2*pi,100);
y=sin(x);z=cos(x); plot(x,y);
title('sin(x)')
figure(2);
plot(x,z);
title('cos(x)');
x=linspace(0,2*pi,100);
y=sin(x); z=cos(x);
a=sin(x).*cos(x);b=sin(x)./(cos(x)+eps);
subplot(2,2,1);plot(x,y),title('sin(x)')
subplot(2,2,2);plot(x,z),title('cos(x)')
subplot(2,2,3);plot(x,a),title('sin(x)cos(x)') subplot(2,2,4);plot(x,b),title('sin(x)/cos(x)')
clear;clc;clf;x=linspace(0,2*pi,30);
y=sin(x);
plot(x,y)
zoom on
x=-3:0.1:3; y=1:0.1:5;
[X,Y]=meshgrid(x,y);
Z=(X+Y).^2;
subplot(2,2,1), mesh(X,Y,Z),
subplot(2,2,2), mesh(X,Y,Z),view(50,-34)
subplot(2,2,3), mesh(X,Y,Z),view(-60,70)
subplot(2,2,4), mesh(X,Y,Z),view([0,1,1])
close all;[x,y,z]=peaks(30);
surf(x,y,z)
axis([-3 3 -3 3 -10 10])
m=moviein(15);
for i=1:15
view(-37.5+24*(i-1),30)
m(:,i)=getframe;
end
movie(m)
theta=linspace(0,2*pi);
rho=sin(2*theta).*cos(2*theta);
polar(theta,rho,'g');
title('Polar plot of sin(2*theta).*cos(2*theta)');
clf
load seamount
scatter(x,y,5,z)
Z=X.*exp(-X.^2-Y.^2); [C,h]=contour(X,Y,Z); clabel(C,h,'manual')
colormap cool
请稍候...
仔细选择要用于标记的等高线。

subplot(1,2,1)
contour3(x,y,z,16,'s')
grid, xlabel('x-axis'),ylabel('y-axis') zlabel('z-axis')
title('contour3 of peaks');
subplot(1,2,2)
contour(x,y,z,16,'s')
grid, xlabel('x-axis'), ylabel('y-axis') title('contour of peaks');
X=[x(:)*.5 x(:)*.75 x(:)];
Y=[y(:)*.5 y(:)*.75 y(:)];
Z=[z(:)*.5 z(:)*.75 z(:)];
S=repmat([1 .75 .5]*10,prod(size(x)),1);
C=repmat([1 2 3],prod(size(x)),1);
scatter3(X(:),Y(:),Z(:),S(:),C(:),'filled'),view(-60,60)。

相关文档
最新文档