– 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.

6 ビュー (過去 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 件のコメント
Korede Akinpelumi
Korede Akinpelumi 2017 年 5 月 16 日
編集済み: Walter Roberson 2017 年 5 月 16 日
function [evens,odds]=assignm
A=randi(51,1,20)+49;
B=50:2:100;
C=51:2:99;
evens=intersect(A,B);
odds=intersect(A,C);
end

サインインしてコメントする。

回答 (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
  2 件のコメント
Rehab Mohamed`
Rehab Mohamed` 2017 年 2 月 9 日
thanks for your answer, but is there any other way to do it? because we haven't learn about (themod) yet, and i really don't know what does it mean. thank you
KSSV
KSSV 2017 年 2 月 9 日
Read about mod. It is very basic. It is called modulo operation.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by