delete empty cells of data array
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Stephen23
il 28 Ago 2017
Modificato: Stephen23
il 28 Ago 2017
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.
Risposte (2)
Guillaume
il 31 Ago 2017
@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) = [];
0 Commenti
Stalin Samuel
il 28 Ago 2017
2 Commenti
Stalin Samuel
il 31 Ago 2017
Modificato: Stalin Samuel
il 31 Ago 2017
You may get some idea from below code
s={'dsfd ' ,'sdfsdf sdfsd sdfsd',' sdfsdfs'}
newStr = erase(s," ")%removes empty spaces
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!