why is my code not working for a particular set of input?

1 visualización (últimos 30 días)
Manav Divekar
Manav Divekar el 1 de Dic. de 2021
Respondida: Rik el 1 de Dic. de 2021
If i give the input, it is working
femaleldlchdrisk([struct('age',22,'ldl',148,'hdl',20,'systolic',120,'diastolic',94,'hasdiabetes',false,'issmoker',true)])
if I give input as; this is not working
femaleldlchdrisk([struct('age',22,'ldl',148,'hdl',20,'systolic',120,'diastolic',94,'hasdiabetes',false,'issmoker',true) struct('age',42,'ldl',178,'hdl',50,'systolic',140','diastolic',104','hasdiabetes',false,'issmoker',true)])
code
function [total] = femaleldlchdrisk(P)
agepts = 0;
ptssum = 0;
if P.age <= 34
agepts = -9;
elseif P.age >=35 && P.age <=39
agepts = -4;
elseif P.age >=40 && P.age <=44
agepts = 0;
elseif P.age >=45 && P.age <=49
agepts = 3;
elseif P.age >=50 && P.age <=54
agepts = 6;
elseif P.age >=55 && P.age <=59
agepts = 7;
elseif P.age >=60 && P.age <=64
agepts = 8;
elseif P.age >=65 && P.age <=69
agepts = 8;
elseif P.age >=70 && P.age <=74
agepts = 8;
elseif P.age >=74
agepts = 8;
end
ptssum = ptssum + agepts;
ldlpts = 0;
if P.ldl < 100
ldlpts = -2;
elseif P.ldl >= 100 && P.ldl <= 129
ldlpts = 0;
elseif P.ldl >= 130 && P.ldl <= 159
ldlpts = 0;
elseif P.ldl >= 160 && P.ldl <= 190
ldlpts = 2;
elseif P.ldl >= 190
ldlpts = 2;
end
ptssum = ptssum + ldlpts;
hdlpts = 0;
if P.hdl < 35
hdlpts = 5;
elseif P.hdl >= 35 && P.hdl<= 44
hdlpts = 2;
elseif P.hdl >= 45 && P.hdl<= 49
hdlpts = 1;
elseif P.hdl >= 50 && P.hdl<= 59
hdlpts = 0;
elseif P.hdl >= 60
hdlpts = -2;
end
ptssum = ptssum + hdlpts;
bppts1 = 0;
if P.systolic < 120
bppts1 = -3;
elseif (P.systolic >= 120 && P.systolic<= 129 )&&(P.diastolic >= 80 && P.diastolic <= 84)
bppts1 = 0;
elseif (P.systolic >= 130 && P.systolic<= 139 )&&(P.diastolic >= 85 && P.diastolic <= 89)
bppts1 = 0;
elseif (P.systolic >= 140 && P.systolic<= 159 )&&(P.diastolic >= 90 && P.diastolic <= 99)
bppts1 = 2;
elseif (P.systolic >= 160)&&(P.diastolic >= 100)
bppts1 = 3;
end
ptssum = ptssum + bppts1;
bppts2 = 0;
if P.diastolic < 80
bppts2 = -3;
elseif (P.diastolic >= 80 && P.diastolic <= 84)
bppts2 = 0;
elseif (P.diastolic >= 85 && P.diastolic <= 89)
bppts2 = 0;
elseif (P.diastolic >= 90 && P.diastolic <= 99)
bppts2 = 2;
elseif (P.diastolic >= 100)
bppts2 = 3;
end
ptssum = ptssum + bppts2;
diabetpts = 0;
if strcmp(P.hasdiabetes, true) %|| P.hasdiabetes == 'Yes'
diabetpts = 4;
elseif strcmp(P.hasdiabetes,false) %|| P.hasdiabetes == 'No'
diabetpts = 0;
end
ptssum = ptssum + diabetpts;
smokerpts = 0;
if strcmp(P.issmoker,true) %|| P.issmoker == 'Yes'
smokerpts = 2;
elseif strcmp(P.issmoker, false) %|| P.issmoker == 'No'
smokerpts = 0;
end
ptssum = ptssum + smokerpts;
total = ptssum;

Respuesta aceptada

Rik
Rik el 1 de Dic. de 2021
Your code doesn't support array inputs.
The easy way to deal with this is what I outline below. Note that this is not the optimal method.
function total = femaleldlchdrisk(P)
if numel(P)>1
for n=1:numel(P)
%this assumes a scalar output
total(n)=femaleldlchdrisk(P(n));
end
return
end
%rest of your function goes here
end

Más respuestas (0)

Categorías

Más información sobre Chemistry en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by