How to apply filters for multiple variables?
9 views (last 30 days)
Show older comments
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 Comment
dpb
on 8 Mar 2021
Use findgroups and splitapply if array data; otherwise put into table and see varfun
Accepted Answer
Jan
on 9 Mar 2021
Edited: Jan
on 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);
More Answers (0)
See Also
Categories
Find more on Simulation, Tuning, and Visualization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!