Separating age into young and old groups
13 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Voss
le 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 commentaires
Voir également
Catégories
En savoir plus sur Software Development Tools dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!