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 CenterFile Exchange에서 Structures에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by