multiple matrix step through for loop
1 view (last 30 days)
Show older comments
Alexander Wilkinson
on 18 Jan 2021
Commented: Bob Thompson
on 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 Comments
Accepted Answer
Bob Thompson
on 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 Comments
Bob Thompson
on 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.
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements 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!