www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/ConstructUniqueStringsforSpecifiedArrayElementsExample.m
%% Construct Unique Elements for Specified Array Indices %% % Create an array of character vectors and make only the first four elements unique. S = {'quiz' 'quiz' 'quiz' 'exam' 'quiz' 'exam'}; U = matlab.lang.makeUniqueStrings(S, 1:4) %% % The first four elements in |U| are unique among themselves, and among % the remaining character vectors in elements 5 and 6 (|'quiz'| and |'exam'|). Alternatively, % you can use a logical array instead of a range of linear indices to achieve % the same results: |U = matlab.lang.makeUniqueStrings(S, [true true true % true false false])| or |U = matlab.lang.makeUniqueStrings(S, logical([1 % 1 1 1 0 0]))|. %% % Append a duplicate |'quiz'| onto the end of |S| and make the first four % elements unique. S{end+1} = 'quiz' U = matlab.lang.makeUniqueStrings(S, 1:4) %% % The character vectors that |makeUniqueStrings| checks are still unique among themselves % and among the remaining elements. Since |makeUniqueStrings| does not check % any elements after element 4, duplicate character vectors remain.