www.gusucode.com > stats 源码程序 matlab案例代码 > stats/CreateAndLabelNominalArraysExample.m

    %% Create and Label Nominal Arrays

%%
% Create nominal arrays from a cell array of character vectors and from
% integer data, and provide explicit labels.

%%
% Create a nominal array from a cell array of character vectors with values |'r'|,
% |'g'|, and |'b'|. Label these levels |'red'|, |'green'|, and |'blue'|,
% respectively. Note that the labels are specified according to the sorted (alphabetical) order of the
% elements in |X|.
X = {'r' 'b' 'g';'g' 'r' 'b';'b' 'r' 'g'}
B = nominal(X,{'blue','green','red'})


%%
% Create a nominal array from integer data with values 1 to 4, merging odd and even values
% into two nominal levels with labels |'odd'| and |'even'|. Achieve the
% merging by duplicating the labels.
X = randi([1 4],5,2)
B = nominal(X,{'odd','even','odd','even'})