function [data, list] = extr_by_var(datastack, variable) % excludes the data that corresponds to the '0's of a binary variable. also % makes a list of the indices of the excluded data. data = datastack; list = zeros(length(variable(:,1)),1); m = 1; for i = length(variable(:,1)):-1:1 if variable(i,1) == 0 data(:,:,i) = []; list(m,1) = i; m = m+1; end end for i = length(list(:,1)):-1:1 if list(i,1) == 0 list (i,:) = []; end end end