Write a function to determine which elements of an array are even numbers (i.e., …, -4, -2, 0, 2, 4, …). Your function should return a logical array of the same size as the input with 1s (TRUE) in the locations corresponding to even numbers.

조회 수: 6 (최근 30일)
How could I solve this?

채택된 답변

Konstantinos Sofos
Konstantinos Sofos 2015년 3월 24일
funvtion Out = findeven(In)
Out = ~mod(In,2)
end
Assuming:
In =
-6 -5 -2 0
1 2 3 4
5 6 7 8
9 10 11 12
Out =
1 0 1 1
0 1 0 1
0 1 0 1
0 1 0 1

추가 답변 (1개)

Meesha Lini Eesan
Meesha Lini Eesan 2015년 3월 24일
A = [-10,-9,-8,-7,-6,-5,-4,-3,-2,1,0,1,2,3,4,5,6,7,8,9,10] % I assign -10 to 10 vector A. B = ~mod(A,2) %I used this function to find the even element using the ~mod function %(modulus) and output to True(1) and False(0)because I use only mod the %output will true(1) will be an odd number.

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by