Creating a column vector form data in table to meet specific requirements.
1 回表示 (過去 30 日間)
古いコメントを表示
Hassen Mohamed Yousif Abdelatif
2021 年 12 月 7 日
I tried so many times to write a vector that meet specific requirements but it gave me scalar.
The requirements are:
If their age is greater than 75 or their BMI is greater than 50 I want the variable risk to 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 I want the variable risk for that subject to 2 (medium risk) and if they don't fit any of the above criteria I would like their risk to 1, signifying low risk.
Notice both (BMI and age are vector of 20x1 double)
My code is
for index=1:length(age)
for index_1=1:length(BMI)
if age>75
risk(high_risk) = 3;
elseif (age>50 & age<=75)
risk(medium_risk) = 2;
elseif (BMI>50)
risk(high_risk) =3;
elseif ( BMI>40 & BMI<=50)
risk(medium_risk)=2
else
risk=1
end
end
end
0 件のコメント
採用された回答
David Hill
2021 年 12 月 7 日
risk=ones(size(age));
risk(age>75|BMI>50)=3;
risk(age>50&age<=75&BMI>40&BMI<=50)=2;
8 件のコメント
Stephen23
2021 年 12 月 8 日
Apparently because only ten participants meet those requirements.
If you have a 20x5 table and select 10 rows from it then you will get a 10x5 table.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Testing Frameworks についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!