Separating age into young and old groups
7 views (last 30 days)
Show older comments
Hello,
I am new to matlab/coding and am having difficulty. I was wondering if it is possible to make a script that seperates my age variable into 2 groups with an age limit of 35. I want to create 2 seperate variables one young and one old that extracts from the age variable for example; ages 35 and younger and classifies it as a 'young' variable and older than 35 as and 'old' variable. Would I need to make and if else statement so that it can classify the age variable into potentially 1= young (35 and younger) and 0=old (older than 35) to then make an index for young and old that extracts the 1's into a young variable and the 0's to an old variable?
Thank you!
0 Comments
Answers (1)
Voss
on 30 Mar 2022
% 50 random ages between 1 and 100:
ages = randi(100,1,50)
% age limit/threshold for separation:
age_limit = 35;
% logical vector saying whether each age is less than or equal to
% age_limit:
is_young = ages <= age_limit;
disp(is_young);
% use logical indexing to separate ages into two new variables:
young_ages = ages(is_young);
old_ages = ages(~is_young);
disp(young_ages);
disp(old_ages);
0 Comments
See Also
Categories
Find more on Software Development Tools in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!