multiple matrix step through for loop
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
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
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 件)
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!