www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/ConstructUniqueStringsandSpecifyExclusionsExample.m
%% Construct Unique Character Vectors and Specify Exclusions %% % Without specifying excluded values, make the character vectors in |U| unique. S = {'John' 'Sue' 'Nick' 'John' 'Campion' 'John' 'Jason'}; U = matlab.lang.makeUniqueStrings(S) %% % Specify that the character vector, |'Nick'|, should be excluded from the output. U = matlab.lang.makeUniqueStrings(S, 'Nick') %% % |makeUniqueStrings| excludes |'Nick'| from |U| and instead modifies the % first duplicate, found in element 3, to be |'Nick_1'|. %% % Exclude workspace variables from the unique cell array. Sue = 42; U = matlab.lang.makeUniqueStrings(S, who) %% % Since |'Sue'| exists in the workspace, |makeUniqueStrings| makes this % character vector unique by appending an underscore and number.