delete empty cells of data array

This might be vary basic but I still need a bit of help to figure this out. I have a relatively large cell array
data={411x7cell 411x7cell 411x7cell 411x7cell 411x7cell ' '}
with data{1,6} being empty. How do I remove/delete this cell from the array. I tried
data(strcmp(' ',data)) = [];
But without luck. Please help... THANKS

5 件のコメント

Stephen23
Stephen23 2017 年 8 月 28 日
編集済み: Stephen23 2017 年 8 月 28 日
Note that the character ' ' is not empty, it has size 1x1.
JB
JB 2017 年 8 月 28 日
That is true and a can fill in any word, but I still don't know how to delete that specific cell from the array
Stephen23
Stephen23 2017 年 8 月 28 日
JB's "Answer" moved here:
Let me rephrase the question. lets say I have this toy array
test = { {'a', 'b', 'c'}, {'d', 'e', 'f'},{''}}
which will give me a {1x3 cell} {1x3 cell} {1x1 cell} array where the last sub-string is empty. How do I delete this empty string so I only end up with
test = { {'a', 'b', 'c'}, {'d', 'e', 'f'}}
Stephen23
Stephen23 2017 年 8 月 28 日
編集済み: Stephen23 2017 年 8 月 28 日
The question originally showed a 1x1 character, now you have a 1x1 cell array containing an empty string. Please actually be precise and define the exact specification of what you want. Changing the specifications does not make it easy to help you.
JB
JB 2017 年 8 月 28 日
I want to delete the 1x1 cell array containing an empty string. Alternatively I can replace the '' with whatever I want like NaN, but the overall aim is to delete the empty string (or NaN string). I hope this help as I am very new to matlab coding.

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

回答 (2 件)

Guillaume
Guillaume 2017 年 8 月 31 日

1 投票

@JB, Stephen's comment is spot on. It may not seem like a big deal to you but your language and your syntax is very imprecise and makes it difficult to answer the question approprietely. There is a big difference between:
data={411x7cell 411x7cell 411x7cell 411x7cell 411x7cell ' '}
and
test = { {'a', 'b', 'c'}, {'d', 'e', 'f'},{''}}
The former is a cell array where some cells may be empty (the others containing cell arrays). Removing those empty cells is trivial:
data(cellfun('isempty', data)) = [];
The latter is a cell array where no cell is ever empty, all cells being themselves cell arrays. Some of these subcell arrays may be empty. Removing these empty cell arrays within cell array is a bit more complicated, since you now need to dig through two cell arrays to test for emptyness:
test(cellfun(@(c) all(cellfun('isempty', c)), test) = [];
Stalin Samuel
Stalin Samuel 2017 年 8 月 28 日

0 投票

Similar discussions

2 件のコメント

JB
JB 2017 年 8 月 28 日
I cant get i to work. My problem is more how to delete substring within string (I think).
Stalin Samuel
Stalin Samuel 2017 年 8 月 31 日
編集済み: Stalin Samuel 2017 年 8 月 31 日
You may get some idea from below code
s={'dsfd ' ,'sdfsdf sdfsd sdfsd',' sdfsdfs'}
newStr = erase(s," ")%removes empty spaces

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

カテゴリ

ヘルプ センター および File ExchangeData Type Identification についてさらに検索

製品

タグ

質問済み:

JB
2017 年 8 月 28 日

回答済み:

2017 年 8 月 31 日

Community Treasure Hunt

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

Start Hunting!

Translated by