how to remove empty cells from a cell array
112 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a cell array of size 11x3815 which contains a lot of empty cells that I would like to get rid of, the cell array looks like this
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1211918/image.png)
We would like to have only the first column of the cell array, and only keep the rows that has cells with contents in them, I tried one method but it gave me the following shape
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1211923/image.png)
which is the first column and under it we have the cells with content, but we need to keep each of them in its original row and not move them , so what is an easy method to do this? I attach the cell aray that I am working on.
THank you in advance
2 comentarios
Image Analyst
el 29 de Nov. de 2022
What if there are two or more columns that have non-empty cells? Would you want to keep all columns that have something in them? Or are you guaranteed that only 0 or 1 column will have a non-empty cell in it?
Respuestas (1)
Arif Hoq
el 29 de Nov. de 2022
a=load("cellArray.mat");
A=a.I;
checkemptycell = any(~cellfun('isempty',A), 1);
output = A(:,checkemptycell)
0 comentarios
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!