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

猜你喜欢

转载自blog.csdn.net/yxnooo1/article/details/112731722