– Generate a vector of 20 random integers, each in the range from 50 to 100. Create a variable evens that stores all of the even numbers from the vector and a variable odds that stores the odd numbers.

11 次查看(过去 30 天)
Can someone please help me solve this problem? I haven't learn about (mod) yet! so please if you can provide me another way to do that will be helpful. Thanks

回答(1 个)

KSSV
KSSV 2017-2-9
编辑:KSSV 2017-2-9
vec = randsample(50:100,20) ; % get 20 random numbers between 50 and 100
themod = mod(vec,2) ; % calculate the mod
even = vec(themod==0) ; % even numbers
odd = vec(themod==1) ; % odd numbers

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by