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

    %% Create and Manipulate Ordinal Arrays
%%
% Create an ordinal array from integer data.

% Copyright 2015 The MathWorks, Inc.

quality = ordinal([1 2 3; 3 2 1; 2 1 3],{'low' 'medium' 'high'})
             
%%
% Identify the elements in |quality| that are members of a level that is
% greater than or equal to |'medium'|. A value of |1| in the resulting array indicates that the corresponding
% element of |quality| is in this category.
quality >= 'medium'
%%
% Identify the elements of |quality| that are members of either |'low'| or
% |'high'|.
ismember(quality,{'low' 'high'})
%%
% Merge the elements of the |'medium'| and |'high'| levels into a new
% level labeled |'ok'|.
quality = mergelevels(quality,{'medium','high'},'ok')

%%
% Display the levels of |quality|.
getlevels(quality)
%%
% Summarize the number of elements in each level. By default, |summary|
% returns counts for each column of the input array.
summary(quality)