matlab cody study notes day2

Some experience:
(1) The difference between else and elseif. If there are only two possibilities, you can only use else after if. If two or more if statements are required, use elseif to indicate that when the condition is judged to be false, the condition is judged again. The two cannot be mixed, the difference must be paid attention to!
(2) When making judgments, such as judging odd and even numbers, if mod(n,2)==0, do not mod(n,2)~=0. Intuitive and convenient.
(3) A very simple program: return all odd bit vectors of the input vector,
for example:
Input x = [5 9 3 2 2 0 -1]
Output y is [5 3 2 -1]
I used if to judge x( i) Whether it is an even number, then assign a value to y, see the comments and use the rem function, which is complicated and difficult to pass. But the answer is actually very simple, only one sentence:
y=x(1:2:end);
this question is very funny, all odd-numbered elements means all odd-numbered elements, I understand it as all odd-numbered elements, so No matter how the code is compiled, it will not pass, and the review of the question is not clear and it is a joke.

Guess you like

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