I'm trying to match people between two different spreadsheets based on certain variables, how can I match them within +/-2?

1 visualización (últimos 30 días)
The purpose is to match people based on their Age, BMI, Sex; but within a deviation of +/-2. I figured out how to create that output but it looks clunky:
for i=1:length(En.SubNumE);
if Pen.AgeP(TargetNum) == En.AgeE(i) || (Pen.AgeP(TargetNum)+1) == En.AgeE(i) || (Pen.AgeP(TargetNum)+2) == En.AgeE(i)
Match(i) = 1; MatchE(j) = En.SubNumE(i); j=j+1;
else
Match(i) = 0;
end
end
is there a less clunky way to do this? Because this is the upper limit, and I realized how clunky it's going to be with additional variables and the lower limit included. I can provide more of the script if this isn't enough context.

Respuestas (1)

Walter Roberson
Walter Roberson el 21 de Dic. de 2019
ismember(Pen.AgeP(TargetNum), En.AgeE(i)+(-2:2)) %only works for discrete
or
Pen.AgeP(TargetNum) >= En.AgeE(i) - 2 && Pen.AgeP(TargetNum) <= En.AgeE(i) + 2 %also works for continuous

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by