📜  我有一个分类数据数组,我需要单元格字符串数据 matlab - 无论代码示例

📅  最后修改于: 2022-03-11 14:55:46.733000             🧑  作者: Mango

代码示例1
% Sample data:
data = categorical({'Pop'; 'Classical'; 'Jazz'; 'Pop'; 'Pop'; 'Jazz'});

% Get unique categories and create indices:
[genre, ~, index] = unique(data)

genre = 

     Classical 
     Jazz 
     Pop 


index =

     3
     1
     2
     3
     3
     2

% Create logical matrix:
mat = logical(accumarray([(1:numel(index)).' index], 1))

mat =

  6×3 logical array

   0   0   1
   1   0   0
   0   1   0
   0   0   1
   0   0   1
   0   1   0