what changes should I make if my input is struct

2 Ansichten (letzte 30 Tage)
Manav Divekar
Manav Divekar am 30 Nov. 2021
Kommentiert: Voss am 30 Nov. 2021
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)])

Akzeptierte Antwort

Voss
Voss am 30 Nov. 2021
Bearbeitet: Voss am 30 Nov. 2021
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 Kommentare
Manav Divekar
Manav Divekar am 30 Nov. 2021
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 am 30 Nov. 2021
if P.issmoker || strcmp(P.issmoker,'Yes')
smokerpts = 2;
else%if ~P.issmoker || strcmp(P.issmoker,'No')
smokerpts = 0;
end
ptssum = ptssum + smokerpts;

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Structures finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by