Removing an empty 1st row from a UITABLE (cell array)

Hi. I have a uitable that I append to and sometime I have an empty 1st row like this:
d=get(handles.uitable1, 'data')
d =
2×6 cell array
{0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double}
{[ 0]} {[ 1798.46]} {[ 1659.30]} {[ 1621.38]} {[ 1521.24]} {[ 57.67]}
Whats the best way to check for this and delete if empty
BTW, its sometimes has an empty 1st row, because sometimes I clear the old data out (that can have more columns than my 6 here) and use the following to reset it:
set(handles.uitable1, 'Data', cell(1,6))
But this leaves
{0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double}

 採用された回答

Bhaskar R
Bhaskar R 2020 年 2 月 5 日

0 投票

d = d(~cellfun(@isempty, d))';

5 件のコメント

Jason
Jason 2020 年 2 月 5 日
Sorry, that doesn't quite work, whilst it removes the empty line, it adds the 2nd and 3rd together
d =
3×6 cell array
{0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double}
{[ 1.00]} {[ 1798.46]} {[ 1659.30]} {[ 1621.38]} {[ 1521.24]} {[ 57.67]}
{[ 2.00]} {[ 2202.82]} {[ 2038.20]} {[ 1994.37]} {[ 1908.88]} {[ 82.31]}
d =
1×12 cell array
{[1.00]} {[2.00]} {[1798.46]} {[2202.82]} {[1659.30]} {[2038.20]} {[1621.38]} {[1994.37]} {[1521.24]} {[1908.88]} {[57.67]} {[82.31]}
Bhaskar R
Bhaskar R 2020 年 2 月 5 日
"Whats the best way to check for this and delete if empty"
That means, if there is only one empty cell in first row, you want to delete that cell only? If yes you will get cell concatanation error. If not can you specify with some more information
Jason
Jason 2020 年 2 月 5 日
編集済み: Jason 2020 年 2 月 5 日
Sorry for any confusion. Its if the entire row is empty as below.
So I want this
{0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double}
{[ 1.00]} {[ 1798.46]} {[ 1659.30]} {[ 1621.38]} {[ 1521.24]} {[ 57.67]}
{[ 2.00]} {[ 2202.82]} {[ 2038.20]} {[ 1994.37]} {[ 1908.88]} {[ 82.31]}
To becom
{[ 1.00]} {[ 1798.46]} {[ 1659.30]} {[ 1621.38]} {[ 1521.24]} {[ 57.67]}
{[ 2.00]} {[ 2202.82]} {[ 2038.20]} {[ 1994.37]} {[ 1908.88]} {[ 82.31]}
Bhaskar R
Bhaskar R 2020 年 2 月 5 日
編集済み: Bhaskar R 2020 年 2 月 5 日
If you want to remove first row of the d
d(1,:) = [];
If you want to remove any row which contains any empty cell
d = d(any(~cellfun(@isempty, d), 2), :);
Jason
Jason 2020 年 2 月 5 日
Perfect, thankyou

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeDevelop Apps Using App Designer についてさらに検索

質問済み:

2020 年 2 月 5 日

編集済み:

2020 年 2 月 5 日

Community Treasure Hunt

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

Start Hunting!

Translated by