what changes should I make if my input is struct

1 view (last 30 days)
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)])

Accepted Answer

Voss
Voss on 30 Nov 2021
Edited: Voss on 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 Comments
Manav Divekar
Manav Divekar on 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 on 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;

Sign in to comment.

More Answers (0)

Categories

Find more on Structures in Help Center and File Exchange

Tags

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!