フィルターのクリア

Seperating evens and odds

4 ビュー (過去 30 日間)
-
- 2015 年 9 月 15 日
編集済み: Walter Roberson 2017 年 5 月 16 日
What would be the method to solve the problem below
Generate a vector of 20 random integers, each in the range of 50 to 100 and store it in vec. Create a variable evens that stores all of the even numbers from the vector, and a variable odds that stores all of the odd numbers.
  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

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

回答 (2 件)

Walter Roberson
Walter Roberson 2015 年 9 月 15 日
x == 2 * floor(x/2)
is true for even numbers and false for everything else

Dan Po
Dan Po 2016 年 10 月 24 日
編集済み: Dan Po 2016 年 10 月 24 日
xevens=x(rem(x,2)==0)
how many ways are there to do this?
  1 件のコメント
Walter Roberson
Walter Roberson 2016 年 10 月 24 日
xevens = x(~rem(x,2));

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

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by