multiple matrix step through for loop

조회 수: 1(최근 30일)
Alexander Wilkinson
Alexander Wilkinson 2021년 1월 18일
댓글: Bob Thompson 2021년 1월 18일
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

채택된 답변

Bob Thompson
Bob Thompson 2021년 1월 18일
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
Bob Thompson
Bob Thompson 2021년 1월 18일
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.

댓글을 달려면 로그인하십시오.

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by