multiple matrix step through for loop
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Alexander Wilkinson
le 18 Jan 2021
Commenté : Bob Thompson
le 18 Jan 2021
i have 3 matricies
age = 66 bmi = 45.9 smoker = 1
70 35.8 0
31 38.1 0
71 44.4 1
57 52.1 1
30 52.1 0
39 47.9 0
52 25.9 1
73 25.4 0
73 28.7 1
I want to identify subjects that are at high risk. Step through each subject in turn. If their age is greater than 75 or their BMI is greater than 50 or they are a smoker, set a variable risk a value of 3, signifying high risk. If their age is greater than 50 and less than or equal to 75 and their BMI is greater than 40 and less than or equal to 50, then set risk for that subject to 2 (medium risk) and if they don't fit any of the above criteria set their risk to 1, signifying low risk. Is it possible to do this in a for loop. I would like the outcome to be a column vector, risk, with a value of 1,2 or 3 for each subject
0 commentaires
Réponse acceptée
Bob Thompson
le 18 Jan 2021
Instead of doing a loop you can just do a bit of logic to the arrays.
risk = ones(length(age),1,1);
risk(age>=75&bmi>=50&smoke==1) = 3;
risk(age>=50&age<75&bmi>=40&bmi<50) = 2;
2 commentaires
Bob Thompson
le 18 Jan 2021
Yup, you could set everything to zero, then have some kind of logic to change things to 1, but it seems unnecessary for the situation you outlined.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Numerical Integration and Differentiation 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!