[422372]: / functions / miscfunc / unique_cell_string.m

Download this file

29 lines (23 with data), 633 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function uniqueStrings = unique_cell_string(c)
% unique string from a cell-array containing only strings, ignores all
% non-strings.
nonStringCells = [];
for i=1:length(c) % remove non-string cells
if ~strcmp(class(c{i}),'char')
nonStringCells = [nonStringCells i];
end
end
c(nonStringCells) = [];
uniqueStrings = {};
for i=1:length(c) % remove non-string cells
if ~isAlreadyEncountered(c{i}, uniqueStrings);
uniqueStrings{end+1} = c{i};
end
end
function result = isAlreadyEncountered(s, u)
result = false;
for i=1:length(u)
if strcmp(u{i}, s)
result = true;
end
end