Answers for "I have a array of catagorical data, I need cell string data matlab"

0

I have a array of catagorical data, I need cell string data matlab

% 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
Posted by: Guest on April-08-2021

Code answers related to "I have a array of catagorical data, I need cell string data matlab"

Browse Popular Code Answers by Language