what changes should I make if my input is struct

2 ビュー (過去 30 日間)
Manav Divekar
Manav Divekar 2021 年 11 月 30 日
コメント済み: Voss 2021 年 11 月 30 日
function [total] = femaleldlchdrisk(age,ldl,hdl,systolic,diastolic,hasdiabetes,issmoker)
agepts = 0;
ptssum = 0;
if age <= 34
agepts = -9;
elseif age ==35 && age<=39
agepts = -4;
elseif age >=40 && age<=44
agepts = 0;
elseif age >=45 && age<=49
agepts = 3;
elseif age >=50 && age<=54
agepts = 6;
elseif age >=55 && age<=59
agepts = 7;
elseif age >=60 && age<=64
agepts = 8;
elseif age >=65 && age<=69
agepts = 8;
elseif age >=70 && age<=74
agepts = 8;
elseif age >=74
agepts = 8;
end
ptssum = ptssum + agepts;
input
femaleldlchdrisk([struct('age',22,'ldl',148,'hdl',20,'systolic',120,'diastolic',94,'hasdiabetes',false,'issmoker',true)])

採用された回答

Voss
Voss 2021 年 11 月 30 日
編集済み: Voss 2021 年 11 月 30 日
function agepts = femaleldlchdrisk(S)
if S.age <= 34
agepts = -9;
elseif S.age <= 39
agepts = -4;
elseif S.age <= 44
agepts = 0;
elseif S.age <= 49
agepts = 3;
elseif S.age <= 54
agepts = 6;
elseif S.age <= 59
agepts = 7;
else
agepts = 8;
end
end
  2 件のコメント
Manav Divekar
Manav Divekar 2021 年 11 月 30 日
How can i change this for struct input
smokerpts = 0;
if P.issmoker == 'true' || P.issmoker == 'Yes'
smokerpts = 2;
elseif P.issmoker == 'false' || P.issmoker == 'No'
smokerpts = 0;
end
ptssum = ptssum + smokerpts;
Voss
Voss 2021 年 11 月 30 日
if P.issmoker || strcmp(P.issmoker,'Yes')
smokerpts = 2;
else%if ~P.issmoker || strcmp(P.issmoker,'No')
smokerpts = 0;
end
ptssum = ptssum + smokerpts;

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by