How to apply filters for multiple variables?

4 visualizaciones (últimos 30 días)
Newbie
Newbie el 8 de Mzo. de 2021
Comentada: Newbie el 9 de Mzo. de 2021
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 comentario
dpb
dpb el 8 de Mzo. de 2021
Use findgroups and splitapply if array data; otherwise put into table and see varfun

Iniciar sesión para comentar.

Respuesta aceptada

Jan
Jan el 9 de Mzo. de 2021
Editada: Jan el 9 de Mzo. de 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);

Más respuestas (0)

Categorías

Más información sobre Simulation, Tuning, and Visualization en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by