Search code examples
arraysmatlabcell-array

Matlab Cell Array Data


I have a cell array it is 100x1, variable name is CellA. As you will see from the png file attached, the cell array contains various size matrices in each of the 100 different cells.

I want to extract that data. Actually, I am trying to find the number of unique elements in each cell and their frequency. Below is my code which gets dimensional errors:

for i=1:length(CellA)
 if isempty(CellA{i})
     continue;% do nothing
 else
     unqmz(i,:) = unique(CellA{i})';
     countmz(i,:) = histc(CellA{i}, unqmz(i))';
 end

Eventually, I want to plot count versus unique number for each different cell array where the total number of counts for that cell exceeds a pre-determined value. e.g.) 4

cell snippet


Solution

  • You can also do it this way:

    unqmz = cellfun(@unique, CellA, 'uni', 0);
    countmz = arrayfun(@(n) histc(CellA{n},unqmz{n}), 1:numel(CellA), 'uni', 0).';