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

1 Ansicht (letzte 30 Tage)
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.

Antworten (1)

Walter Roberson
Walter Roberson am 21 Dez. 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

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by