How to apply filters for multiple variables?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi. I want to filter some subjects with some variables and then for the filtered subjects (rearidx) I want to add another filter (injuryidx). How do I perform this? This is my current code. Thanks
%Get rearfoot and Midfoot strikers
rearidx = [];
mididx = [];
for i=2:n
if ~ismember(i, excludeidx)
if strcmp(metadata.footstrike{i}, 'RFS')
rearidx(end + 1) = i;
elseif strcmp(metadata.footstrike{i}, 'MFS')
mididx(end+1) = i;
end
end
end
[j,k] = size(rearidx);
% get healthy vs injured indicies
injuryidx = [];
healthyidx = [];
for i=2:k
if ~ismember(i, excludeidx)
if strcmp(metadata.injury_status{i}, 'injured')
injuryidx(end + 1) = i;
elseif strcmp(metadata.injury_status{i}, 'healthy')
healthyidx(end+1) = i;
end
end
end
1 commentaire
dpb
le 8 Mar 2021
Use findgroups and splitapply if array data; otherwise put into table and see varfun
Réponse acceptée
Jan
le 9 Mar 2021
Modifié(e) : Jan
le 9 Mar 2021
In the 2nd loop, i is running over the number of elements of rearindex. Comparing it with the excludeidx is not matching anymore.
%Get rearfoot and Midfoot strikers
includeidx = setdiff(2:n, excludeidx);
isrear = strcmp(metadata.footstrike(includeidx), 'RFS');
readidx = includeidx(isrear);
ismid = strcmp(metadata.footstrike(includeidx), 'MFS');
mididx = includeidx(ismid);
% Healthy modfoot strikers:
ishealthy = strcmp(metadata.injury_status(readidx), 'healthy');
rearhealthyidx = readidx(ishealthy);
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Workspace Variables and MAT Files 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!