机器学习入门第四篇——Octave/Matlab Tutorial(4)

机器学习入门第四篇——Octave/Matlab Tutorial(4)

  • Compution on Data
  • Ploting Data

Compution on Data

A=magic(3) % 魔方阵,它们所有的行和列和对角线加起来都等于相同的值 
% The magic function returns these matrices called magic squares mathematical property that
% all their row and columns and diagonals sum up to the same thing.

 [r,c]=find(A>=7) % 找元素大于等于7的行和列

在这里插入图片描述

sum(a) % 求和
prod(a) % 求积
ceil(a)  % 向上四舍五入
floor(a) % 向下四舍五入

在这里插入图片描述


rand(3) % 随机函数,产生了一个3*3的随机矩阵
 max(rand(3),rand(3)) % 在产生的3*3的随机矩阵中找到最大的,再组成一个3*3的矩阵
max(A,[],2) % takes the per row maximum
 max(A,[],1) % takes the column wise maxmum
 max(A) % takes the column wise maxmum
 max(max(A)) % A中最大值
 A(:) % turn A into a vector

在这里插入图片描述

在这里插入图片描述

A=magic(9)
sum(A ,1)
sum(A ,2)
sum(sum(A .* eye(9))) % 对角线元素之和
sum(sum(A.*flipud(eye(9)))) % flipud stand for flip up down 斜对角线元素之和

在这里插入图片描述在这里插入图片描述


A=magic(3)
pinv(A) % pseudo - inverse 逆矩阵

在这里插入图片描述


Ploting Data

t=[0:0.01:0.98]; % 步长为0.01的0-0.98长度

在这里插入图片描述


y=sin(2*pi*4*t);
plot(t,y) % 画sin函数

在这里插入图片描述


y2=cos(2*pi*4*t);
plot(t,y2) % 画cos函数

在这里插入图片描述


plot(t,y2,'r'); % ' r ' 表示红色 red,cos函数画红色
hold on; %开着cos函数的图
plot(t,y,'g'); % ' g ' 表示绿色 green,sin函数画绿色
xlabel('time') % 给x贴上time的标签
ylabel('value') % 给y贴上value的标签
legend('sin','cos') % 标记两个函数

在这里插入图片描述


 title('myPlot') % 题目
cd 'D:';print -dpng 'myPlot.png' % 保存图片到D盘

在这里插入图片描述


 figure(2);plot(t,y2); 
 figure(1);plot(t,y);
 % 两张图片同时打开

在这里插入图片描述


subplot(1,2,1) % Divides plot grid, access first element.
plot(t,y);
subplot(1,2,2); % Divides plot grid, access second element.
plot(t,y2); % 将sin和cos放在同一张图片中,但是是两个不同的坐标
axis([0.5 1 -1 1]) % 更改坐标

在这里插入图片描述


clf; % 清除图像

在这里插入图片描述

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值