Skip to content

Commit

Permalink
'exact' flag added to select_atlas_subset
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-Sun committed Sep 4, 2023
1 parent cfbb42b commit 70886ff
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions CanlabCore/@atlas/select_atlas_subset.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
% 'labels_2' : If you enter any field name in the object, e.g., labels_2,
% the function will search for keyword matches here instead of in obj.labels.
%
% 'exact' : If you enter 'exact', function will not look for overlaps in
% names, and only look for exact string matches.
%
% Examples:
%
% atlasfile = which('Morel_thalamus_atlas_object.mat');
Expand Down Expand Up @@ -59,6 +62,9 @@
% Edited by tor, 12/2019, to use any field to select labels; and update
% auxiliary label fields too.
%
% Edited by Michael Sun, 09/04/2023, added an 'exact' flag, so that users
% can select to match string labels exactly and not capture regions with
% overlapping labels e.g., Cblm_Vermis_VI and Cblm_Vermis_VII.

% -------------------------------------------------------------------------
% DEFAULTS AND INPUTS
Expand All @@ -67,6 +73,7 @@
strings_to_find = [];
integers_to_find = [];
doflatten = false;
doexact=false;

% for entry of optional field to search for keywords
myfields = fieldnames(obj);
Expand All @@ -87,6 +94,7 @@
case 'flatten', doflatten = true;

% case 'xxx', xxx = varargin{i+1}; varargin{i+1} = [];
case 'exact', doexact = true;

otherwise

Expand Down Expand Up @@ -117,14 +125,22 @@
for i = 1:length(strings_to_find)

% Find which names match
wh = ~cellfun(@isempty, strfind(obj.(mylabelsfield), strings_to_find{i}));
if strmatch(mylabelsfield, 'label_descriptions')
wh=wh';
if doexact == false
wh = ~cellfun(@isempty, strfind(obj.(mylabelsfield), strings_to_find{i}));
if strmatch(mylabelsfield, 'label_descriptions')
wh=wh';
end

to_extract = to_extract | wh;
% Addition by Michael Sun 09/04/2023: Match strings exactly
else
wh = strcmp(obj.(mylabelsfield), strings_to_find{i});
if strmatch(mylabelsfield, 'label_descriptions')
wh=wh';
end

to_extract = to_extract | wh;
end


to_extract = to_extract | wh;

end

% -------------------------------------------------------------------------
Expand Down

0 comments on commit 70886ff

Please sign in to comment.