huppertt / nirs-toolbox

Toolbox for fNIRS analysis
91 stars 61 forks source link

multiple varToMatch broken in AddDemographics module #51

Open bzinszer opened 2 months ago

bzinszer commented 2 months ago

Commit #https://github.com/huppertt/nirs-toolbox/commit/bd7206038069c8888eaf721ab2800f70720851c5 to automatically fill varToMatch in +nirs/+modules/AddDemographics.m seems to have broken support for cases where length(obj.varToMatch)>1.

The problem seems to mainly be on line 46 because comparing two cell arrays is not supported in strcmpi. I believe there is a simple fix: Use ismember instead of strcmpi (and add lower so it's still case insensitive): varToMatchA_idx=find(ismember(lower(obj.demoTable.Properties.VariableNames),lower(obj.varToMatch)));

This fix requires two additional changes.

  1. On line 59, capture the case where obj.varToMatch is a cell containing only one column name: if ~iscell(obj.varToMatch) || length(obj.varToMatch)==1
  2. On line 76 expand the obj.varToMatch cell array. (Lines 59 and 72 already require that obj.varToMatch is a cell array already to reach this point). T = cell2table(data(i).demographics(obj.varToMatch{:}),'VariableNames',varToMatchA);