matlab简单绘图,MATLAB简单绘图

简单函数图:

x = 0:0.05:5;

y = sin(x.^2);

plot(x,y)

合并函数作图

x = 0:0.05:5;

y1 = sin(x.^2);

y2 = cos(x.^2);

plot(x,y1,x,y2)

条形图

x = -2.9:0.2:2.9;

y = exp(-x.*x);

bar(x,y)

子模块画图

%Define the data.

x = linspace(0,10);

y1 = sin(x);

y2 = sin(2*x);

y3 = sin(4*x);

y4 = sin(8*x);

%Plot the four sine waves and title each subplot.

figure

subplot(2,2,1)

plot(x,y1)

title('Subplot 1: sin(x)')

subplot(2,2,2)

plot(x,y2)

title('Subplot 2: sin(2x)')

subplot(2,2,3)

plot(x,y3)

title('Subplot 3: sin(4x)')

subplot(2,2,4)

plot(x,y4)

title('Subplot 4: sin(8x)')

你能看到效果如下:

7246b7f92955?nomobile=yes

Paste_Image.png

画图之中,你可能需要修改线型、颜色、点型。请你务必仔细参考:LineSpec (Line Specification)这篇文章。

这里的.是数组运算符,意思是对应位置的元素做计算。

你可以试试下面的计算你就知道什么意思了:

a = pascal(4)

b = inv(a)

c = a*b %矩阵乘法,肯定得到单位阵eye(4)

d = a.*b %做数组运算,对应位置的元素计算,跟矩阵乘法完全不一样。就是简单的数组乘法。

还有下面的例子

x = 1:5

得到:

x =

1 2 3 4 5

进而计算x.^2

得到:

ans =

1 4 9 16 25

这就是数组运算符。

于是你便知道了,你如果计算

x.^3

你会得到:

ans =

1 8 27 64 125

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值