フィルターのクリア

how to remove empty cells from a cell array

75 ビュー (過去 30 日間)
Manar Anwar
Manar Anwar 2022 年 11 月 29 日
編集済み: Manar Anwar 2022 年 11 月 29 日
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
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
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 件のコメント
Image Analyst
Image Analyst 2022 年 11 月 29 日
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?
Manar Anwar
Manar Anwar 2022 年 11 月 29 日
編集済み: Manar Anwar 2022 年 11 月 29 日
Yes, I want keep all columns that have something in them, I know a cell array can't have a variable length for each row, so each row will have the size of the row that has more cells with contents but that is fine even if we still had some epmty cells there to do this, it will not be a huge problem. I just want to reduce the cell array to a shape where we can clearly identify the cells in each row.

サインインしてコメントする。

回答 (1 件)

Arif Hoq
Arif Hoq 2022 年 11 月 29 日
a=load("cellArray.mat");
A=a.I;
checkemptycell = any(~cellfun('isempty',A), 1);
output = A(:,checkemptycell)
output = 11×8 cell array
{[103]} { 0×8 double} { 0×8 double} { 0×8 double} { 0×8 double} { 0×8 double} { 0×0 double} { 0×0 double} {[104]} { 0×8 double} { 0×8 double} { 0×8 double} { 0×8 double} { 0×8 double} { 0×0 double} { 0×0 double} {[109]} { 0×8 double} { 0×8 double} { 0×8 double} { 0×8 double} { 0×8 double} { 0×0 double} { 0×0 double} {[132]} { 0×8 double} { 0×8 double} { 0×8 double} { 0×8 double} { 0×8 double} { 0×0 double} { 0×0 double} {[133]} { 0×8 double} { 0×8 double} { 0×8 double} { 0×8 double} { 0×8 double} { 0×0 double} { 0×0 double} {[166]} { 0×8 double} { 0×8 double} { 0×8 double} { 0×8 double} { 0×8 double} { 0×0 double} { 0×0 double} {[167]} {355×8 double} { 0×8 double} { 0×8 double} { 0×8 double} { 0×8 double} { 0×0 double} { 0×0 double} {[168]} { 0×8 double} { 0×8 double} { 0×8 double} { 0×8 double} { 0×8 double} {493×8 double} {493×8 double} {[341]} { 0×8 double} { 0×8 double} { 0×8 double} { 0×8 double} { 0×8 double} { 0×0 double} { 0×0 double} {[342]} { 0×8 double} { 0×8 double} { 0×8 double} {455×8 double} {455×8 double} { 0×0 double} { 0×0 double} {[343]} { 0×8 double} {490×8 double} {490×8 double} { 0×8 double} { 0×8 double} { 0×0 double} { 0×0 double}

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by