Skip to content

Commit

Permalink
allow for strings at more occations
Browse files Browse the repository at this point in the history
  • Loading branch information
ralfHielscher committed Mar 8, 2025
1 parent fff703c commit 2ff4812
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
8 changes: 4 additions & 4 deletions EBSDAnalysis/@EBSD/subsind.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
if numel(subs)==2 && all(cellfun(@isnumeric, subs))
ind = ebsd.findByLocation([subs{:}]);
return
elseif numel(subs)==2 && ischar(subs{1}) && strcmpi(subs{1},'id')
elseif numel(subs)==2 && (ischar(subs{1}) || isstring(subs{1})) && strcmpi(subs{1},'id')
ind = ebsd.id2ind(subs{2});
if any(ind(:)==0)
error('No data with the specified ids in the data set');
end
return
elseif numel(subs)==3 && ischar(subs{1}) && strcmpi(subs{1},'xy')
elseif numel(subs)==3 && (ischar(subs{1}) || isstring(subs{1})) && strcmpi(subs{1},'xy')
ind = ebsd.findByLocation(subs{2},subs{3});
if any(ind(:)==0)
error('No data with the specified coordinates in the data set');
Expand All @@ -29,7 +29,7 @@
ind = ind & ebsd.isIndexed;

% ebsd('mineralname') or ebsd({'mineralname1','mineralname2'})
elseif ischar(subs{i}) || iscellstr(subs{i})
elseif ischar(subs{i}) || iscellstr(subs{i}) || isstring(subs{i})

mineralsSubs = ensurecell(subs{i});
phaseNumbers = cellfun(@num2str,num2cell(ebsd.phaseMap(:)),'Uniformoutput',false);
Expand All @@ -53,7 +53,7 @@
if ~any(phases)
disp(' ');
warning off backtrace
warning(['There is no such phase "' mineralsSubs{1} '". Maybe you mispelled it?']);
warning("There is no such phase " + mineralsSubs{1} + ". Maybe you mispelled it?");
warning on backtrace
end

Expand Down
5 changes: 2 additions & 3 deletions EBSDAnalysis/@grain2d/private/subsind.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@

ind = ind & grains.isIndexed;

elseif ischar(subs{i}) || iscellstr(subs{i})


elseif ischar(subs{i}) || iscellstr(subs{i}) || isstring(subs{i})

phases = false(length(grains.phaseMap),1);
mineralsSubs = ensurecell(subs{i});
phaseNumbers = cellfun(@num2str,num2cell(grains.phaseMap(:)),'Uniformoutput',false);
Expand Down
2 changes: 1 addition & 1 deletion EBSDAnalysis/@grainBoundary/subsref.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
subs = s(1).subs;

% turn phaseNames into crystalSymmetry
isCS = cellfun(@(x) ischar(x) | isa(x,'crystalSymmetry'),subs);
isCS = cellfun(@(x) ischar(x) | isstring(x) | isa(x,'crystalSymmetry'),subs);
phId = cellfun(@gB.name2id,subs(isCS));
isCS(isCS) = phId>0; phId(phId==0) = [];
subs(isCS) = gB.CSList(phId);
Expand Down
2 changes: 1 addition & 1 deletion EBSDAnalysis/@triplePointList/private/subsind.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
end

% select for minerals
isMineralName = cellfun(@ischar,subs);
isMineralName = cellfun(@(x) ischar(x) | isstring(x),subs);
if any(isMineralName)
ind = gB.hasPhase(subs{isMineralName});
end
Expand Down
6 changes: 3 additions & 3 deletions EBSDAnalysis/phaseList.m
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@

function id = cs2phaseId(pL,cs)

if ischar(cs) && strcmpi(cs,'notIndexed')
if (ischar(cs) || isstring(cs)) && strcmpi(cs,'notIndexed')
id = 1;
return;
elseif ~isa(cs,'crystalSymmetry')
Expand All @@ -367,11 +367,11 @@
function phId = name2id(pL,ph)
% convert phase name to id

if ischar(ph)
if ischar(ph) || isstring(ph)
alt_mineral = cellfun(@num2str,num2cell(pL.phaseMap),'Uniformoutput',false);
ph = strrep(ph,')','\)');
ph = strrep(ph,'(','\(');
ph = ~cellfun('isempty',regexpi(pL.mineralList(:),['^' ph])) | ...
ph = ~cellfun('isempty',regexpi(pL.mineralList(:),"^" + ph)) | ...
strcmpi(alt_mineral(:),ph);
phId = find(ph,1);
if isempty(phId), phId = 0; end
Expand Down

0 comments on commit 2ff4812

Please sign in to comment.