Octave/matlab 语句:第二篇

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;

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值