matlab cody study notes day6 isempty and intersect function usage

Some learning experience:
(1) Cylindrical surface area:
cylindrical surface area = side area + two base areas = 2πrh+2πr^2
(2) Conversion between Fahrenheit and Celsius:
C = (F–32) * 5/9;
( 3) Find the perfect square
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.
Code:
b=(~isempty(intersect(a.^2,a)));

Simply study the isempty and intersect functions:
① The isempty(A) function is a function to determine whether the sequence A is empty.
The usage of this function is as follows:
C = isempty(A):
If A is empty, the returned value is 1
If A is not empty, the returned value is 0
D = ~isempty(A)
is the opposite of the above, if A If it is empty, the returned value is 0. If A is non-empty, the returned value is 1.
It is emphasized here that an empty element represents an unassigned element, and 0 is not an empty element.
②The intersect function is used as follows:
[c, ia, ib] = intersect(A, B);
This function returns the intersection of AB, and ia, ib returns the index of the array where the intersection is located.
Example: A=[2 3 4]; B=[4];
[c, ia, ib] = intersect(A, B);
get c=[4]
The index of c in array A is ia=3
c in array The index of B is ib=1

Guess you like

Origin blog.csdn.net/yxnooo1/article/details/112731722