what changes should I make if my input is struct

2 vues (au cours des 30 derniers jours)
Manav Divekar
Manav Divekar le 30 Nov 2021
Commenté : Voss le 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)])

Réponse acceptée

Voss
Voss le 30 Nov 2021
Modifié(e) : Voss le 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 commentaires
Manav Divekar
Manav Divekar le 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 le 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;

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Tags

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by