multiple matrix step through for loop

1 visualizzazione (ultimi 30 giorni)
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

Risposta accettata

Bob Thompson
Bob Thompson il 18 Gen 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 Commenti
Alexander Wilkinson
Alexander Wilkinson il 18 Gen 2021
thanks
so the first line has set all subjects to value 1 and then they just get changed to 2 or 3 depending on if they fit into the category
Bob Thompson
Bob Thompson il 18 Gen 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.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by