I'm trying to match people between two different spreadsheets based on certain variables, how can I match them within +/-2?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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.
0 commentaires
Réponses (1)
Walter Roberson
le 21 Déc 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
0 commentaires
Voir également
Catégories
En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!