matlab cody学习笔记 day6 isempty和intersect函数的用法

一些学习心得:
(1)圆柱表面积:
圆柱的表面积=侧面积+两个底面积=2πrh+2πr^2
(2)华氏度与摄氏度的转换:
C = (F–32) * 5/9;
(3)寻找完美的平方
Given a vector of numbers, return true if one of the numbers is a square of one of the other numbers. Otherwise return false.
Example:
Input a = [2 3 4]
Output b is true
Output is true since 2^2 is 4 and both 2 and 4 appear on the list.
代码:
b=(~isempty(intersect(a.^2,a)));

简单学习一下isempty和intersect函数:
①isempty(A)函数是一个判断数列A是否为空的一个函数。
对于这个函数的用法如下:
C = isempty(A):
假如A为空的话,返回的值是1
假如A为非空的话,返回的值是0
D = ~isempty(A)
与上面相反,假如A为空的话,返回的值是0,假如A为非空的话,返回的值是1
在这里强调一下,空元素代表的是未赋值的元素,0并不是空元素。
②intersect函数用法如下:
[c, ia, ib] = intersect(A, B);
这个函数是c返回A B的交集,ia,ib返回的是 交集 所在 数组的指标。
例:A=[2 3 4]; B=[4];
[c, ia, ib] = intersect(A, B);
得到 c=[4]
c在数组A的指标为ia=3
c在数组B的指标为ib=1

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值