I have a 32*1 cell array. How I can convert it to categorical?
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Risposte (1)
Jon
il 2 Giu 2022
Modificato: Jon
il 2 Giu 2022
You could do something like this:
% As an example make a cell array whose elements are random matrices
numMatrices = 10; % number of matrices in cell array
matrixSize = 3; % size of square matrices
A = cell(numMatrices,1); % preallocate
for k = 1:numMatrices
A{k} = randn(matrixSize);
end
% Obtain a single scalar value to characterize each matrix
% ( for example I took largest element, but you need to adapt for your
% problem)
v = cellfun(@(X) max(abs(X(:))),A);
% turn it into a categorical vector
binEdges = [0,1,2,3];
categories = {'small','medium','large'}
Ac = discretize(v,binEdges,"categorical",categories)
Note, I am assuming that you are going to provide a function that turns each matrix in your cell array to a double (non-integer) value, that is why I used the function discretize to bin them. If your function turns each matrix in your cell to an integer you could use the function categorical instead
0 Commenti
Vedere anche
Categorie
Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!