t=[0:0.01:0.98];
y1=sin(2*pi*4*t); %正弦函数
plot(t,y1); %t为x轴,y1为y轴
y1=sin(2*pi*4*t);
y2=cos(2*pi*4*t);
plot(t,y1);
hold on; %将y1和y2同时显示在同一个图上
plot(t,y2,'r'); %r表示用红色绘制
xlabel('time'); %time显示x轴
ylabel('value'); %value显示y轴
legend('sin','cos'); %标识第一条线为sin,第二条线为cos
title('my plot') %图形标题
print -dpng 'myPlot.png' %保存图像
figure(1); plot(t,y1);
figure(2); plot(t,y2); %将两个函数绘制成两个图
subplot(1,2,1); %前两个参数:将图像分成一个1*2的格子,最后一个参数:使用第一个格子。
plot(t,y1); %图像显示在第一个格子
subplot(1,2,2); %使用第二个格子
plot(t,y2);
axis([0.5 1 -1 1]) %改变坐标的刻度:X轴为0.5~1,Y轴为-1~1
A=magic(5) %5*5的矩阵
imagesc(A) %将矩阵A绘制成5*5的彩色格图
for i=1:10,
v(i)=2^i;
end;
i=1;
while i<=5,
v(i)=100;
i=i+1;
end;
%while语句
while true,
v(i)=999;
i=i+1;
if i==6,
break;
end; %结束if语句
end; %结束while语句
% if else 语句
v(1)=2;
if v(1)==1,
disp('The value is one');
elseif v(1)==2,
disp('The value is two');
else
disp('The value is not one or two.');
end;