一、数据绘制
1、三角函数
设定区间t=[0:pi/20:2*pi] //从0开始,到2*pi为结束,以pi/20为区间间隔,绘制图像
设定函数:y1=sin(t)
绘制函数:plot(t,y1)
保留函数,在y1图像上绘制y2:hold on
设定函数:y2=cos(t)
绘制函数:plot(t,y2)
设置x坐标:xlabel("time")
设置y坐标:ylabel("value")
标记出两个函数:legend('sin','cos')
设置标题:title("XXX")
保存为某路径下的png文件:cd 'c:\users\``````'; print -dpng 'XXX.png'
在两个窗口绘制两个图像:figure(1):plot(t,y1)
figure(2):plot(t,y2)
在一个窗口绘制多个不重叠图像:subplot(1,2,1);//将窗口分出一个1*2的方格图,且使用左边开始第一个方格开始绘图
plot(t,y1)//在左边开始第一个方格绘制y1
subplot(1,2,2)//开始使用左边开始第二个方格开始绘图
plot(t,y2)//在左边开始第二个方格绘制y2
重新设置图中x,y轴的范围:axis([x1,x2,y1,y2])//将图中x设为x1~x2,y设为y1~y2。
清空图像:clf
关闭窗口:close
2、将矩阵可视化
A=magic(5)
imagesc(A)
二、控制语句
1、for循环
v=zeros(10,1);
for i =1:10,%此处是逗号
v(i)=i;
end;%end不可少,此处是分号
2、while循环
i=1;
while true,
v(i)=1;
i=i+1;
if i>=5,
break;
end;
end;
3、if语句
if v(i)==1,
disp("it is 1");
elseif v(i)==2,
disp("it is 2");
else
disp("it is other numbers");
end;
BY ZJQ