Seperating even/odd numbers from an array using doc mod

2 ビュー (過去 30 日間)
Angel Carrillo
Angel Carrillo 2015 年 4 月 15 日
コメント済み: Image Analyst 2015 年 4 月 15 日
I have an excel file that I imported into MatLab using xlsread.... this file has numbers ranging from 1000-5999 and has over 5000 individual elements in it.
The basics of the question is that all odd numbers are men and even numbers are women. How can I write a script using the remainder tool on Matlab??
The output must look something similiar to this(with different numbers):
The total # of habitants in Tiny Ville is = 10
Tiny Ville has = 8 women
Tiny Ville has = 2 men

採用された回答

Image Analyst
Image Analyst 2015 年 4 月 15 日
Use the length() or size() function to get the total. Use the rem() function to calculate the number of men and women. Use the fprintf() function to print out your results to the command window. You can replace "is = " with just "is" or with just "=" because you don't need both - it doesn't sound right. Same for "has =".
  2 件のコメント
Angel Carrillo
Angel Carrillo 2015 年 4 月 15 日
Would it be easiest to use an if else if structure?
Image Analyst
Image Analyst 2015 年 4 月 15 日
No. Why would it be? How could it be easier than this (partial code hint):
allPeople = [1,2,3,4,5,6];
men = rem(allPeople, 2)

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

その他の回答 (0 件)

カテゴリ

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