How to apply filters for multiple variables?

9 次查看(过去 30 天)
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 个评论
dpb
dpb 2021-3-8
Use findgroups and splitapply if array data; otherwise put into table and see varfun

请先登录,再进行评论。

采纳的回答

Jan
Jan 2021-3-9
编辑:Jan 2021-3-9
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);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulation, Tuning, and Visualization 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by