cmd | |
---|---|
clc | 清空屏幕 |
向量表示
x=[1,2,3]
x=[1 2 3]
矩阵
x=[1 2 3:4 5 6]
AB矩阵乘法
A.B对应相乘
脚本编写
1
x=input('please input x:');
x
2
fprintf('%f\n',x); %g
if
if num>0
fprintf~~~;
else if
print~~~~;
else if ~~&&~
fprintf~~~;
end
disp();
disp(['apple',' ','banana','orange']),
while
while 条件
循环体
end
for i=5:-1:-5
script function
function result mysum(a)
result=a;
end
画图
plot(x,y);折线图
x=-3:3;
y1=x.*x
y2=x^3
plot(x,y);
plot(x,y1,'green',x,y2,'black');
plot(x,y1,'green-o',x,y2,'black');
axis equal
bar(y) 直方图
bar(x,y)
plot3(x,y,z) 三维图像
plot(x1,y1);
hold on不重置窗口
plot(x2,y3);
gird on显示网格
title('x^2 vs x^3');
xlable('x-axis')
ylable('y-axis')
subplot
subplot(2.3.1) 2行3列
plot(x,y1);
subplot(2,2,[3.4]);合并
surf(x,y,z);
[X,Y]=meshgrid(x,y)
set
例子:
不会动的正弦
x=-pi:0.1:pi;
y=sin(x);
plot(x,y);
会动的
h=plot(x,y);
for i=1:100
x=x+0.1;
y=sin(x);
set(h,‘xData’,x,‘YData’,y)
drawnow
end
while true
x=x+0.1;
y=sin(x);
set(h,‘xData’,x,‘YData’,y)
drawnow
end
h=plot(x,y,z);
axis=a([-1,1,-1,1,-40,40])
for i=1:100
z=0.98*z;
set(h,‘xData’,x,‘YData’,y,'XZData',z);
drawnow
end
t=0:0.1:2*pi;
x=con(t);
y=sin(t);
plot(x,y);
hold on;
axis equal;
linex=[0.1];
lineY=[0.0];
plot(linex,liney);
theta=theta+0.1;
linex(2)=cos(theta);