In a cell array, how I can count the number of cells in each column?

Hello, I’m doing a statistical analysis however gotte deal with these kinds of arrays. The idea is to get a vector with the number of cells in each column of the cell array (attached). Thanks.

 Réponse acceptée

cellfun('length',locs)

6 commentaires

@Matt J and how can I display the values inside of each cell in a table (columns and rows)?
Matt J
Matt J le 27 Mai 2021
Modifié(e) : Matt J le 27 Mai 2021
You would have to pad the cell contents to a common length, e.g., with NaNs. Then you could use cell2table().
@Matt J I have tried, but it does'n work like that. if you use the 'cell2table' function you will get a different result ,, I need soemthing like the one in the picture, showing independently the results of each cell.
Here is a simpler example:
locs{1}=[84.6 nan nan nan];
locs{2}=[84.9 87 87.9 87.6];
locs{3}=[83.1, 84 nan nan];
array2table(cell2mat(locs(:)))
ans = 3×4 table
Var1 Var2 Var3 Var4 ____ ____ ____ ____ 84.6 NaN NaN NaN 84.9 87 87.9 87.6 83.1 84 NaN NaN
@Matt J it works good because previously you created locs{1}, locs{2} etc… but the attached file is just a cell array , once I use this : array2table(cell2mat(locs(:))) it shows all the values in just one column, however if you notice in the cell array there are just 24 columns, with different rows, (every cell has a different number), it cannot be all in just one column. Thanks for your help.
@Matt J For example, Using writecell(locs’,filename,’sheet’,1) works so good, but the matter is that this function is only to create a .xls file, and I need this in at least .mat extension.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Statistics and Machine Learning Toolbox dans Centre d'aide et File Exchange

Produits

Version

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by