How to apply filters for multiple variables?

9 ビュー (過去 30 日間)
Newbie
Newbie 2021 年 3 月 8 日
コメント済み: Newbie 2021 年 3 月 9 日
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);
  1 件のコメント
Newbie
Newbie 2021 年 3 月 9 日
Thanks Jan. Will try this

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSimulation, Tuning, and Visualization についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by