How do I sort excel data by Age
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I'm trying to use a loop to seperate the excel data that has ages from 14-90 years old. I need to seperate those numbers into group of young (14-25), medium (26-64) and old (65-90). How would I use a loop to do this?
This is the code I have so far:
syms i
cond = i <= 25;
for i = 1:1:100
if subs(cond, i)
disp (i)
end
end;
The output just consists of matlab listing the numbers 1 to 25.
0 Commenti
Risposta accettata
LeoAiE
il 2 Mag 2023
Hi,
Let me know if that's what you looking for!
% Assuming you have an array "ages" containing the age values from the Excel file
ages = [14 20 30 45 65 75]; % Replace this with your actual data from the Excel file
young = [];
medium = [];
old = [];
for i = 1:length(ages)
age = ages(i);
if age >= 14 && age <= 25
young = [young, age];
elseif age >= 26 && age <= 64
medium = [medium, age];
elseif age >= 65 && age <= 90
old = [old, age];
end
end
disp('Young ages:');
disp(young);
disp('Medium ages:');
disp(medium);
disp('Old ages:');
disp(old);
2 Commenti
LeoAiE
il 3 Mag 2023
I don't have your data but you can use a similar method to separate the COVID results based on the age groups. Assuming you have an array "covid_results" containing the COVID result values (1 or 0) corresponding to the ages in the "ages" array,
% Replace these example data with your actual data from the Excel file
ages = [14 20 30 45 65 75];
covid_results = [1 0 1 1 0 1];
young_covid = [];
medium_covid = [];
old_covid = [];
for i = 1:length(ages)
age = ages(i);
covid_result = covid_results(i);
if age >= 14 && age <= 25
young_covid = [young_covid, covid_result];
elseif age >= 26 && age <= 64
medium_covid = [medium_covid, covid_result];
elseif age >= 65 && age <= 90
old_covid = [old_covid, covid_result];
end
end
young_positives = sum(young_covid);
medium_positives = sum(medium_covid);
old_positives = sum(old_covid);
disp('COVID positives in young age group:');
disp(young_positives);
disp('COVID positives in medium age group:');
disp(medium_positives);
disp('COVID positives in old age group:');
disp(old_positives);
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!