deleting all rows from a table that contain a string
22 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have the following table T:
LastName Age Smoker Height Weight BloodPressure
_________ ___ ______ ______ ______ _____________
empty empty empty empty empty empty
'Sanchez' 38 true 71 176 124 93
empty empty empty empty empty empty
'Johnson' 43 false 69 163 109 77
empty empty empty empty empty empty
'Li' 38 true 64 131 125 83
empty empty empty empty empty empty
'Diaz' 40 false 67 133 117 75
empty empty empty empty empty empty
'Brown' 49 true 64 119 122 80
empty empty empty empty empty empty
I want to remove all the rows that contain the string 'empty'. I've searched but the examples I found was to search on a particular column but I want to search on all columns.
T(cellfun(@isempty, strfind(T.columnName, 'empty')), :);
0 Commenti
Risposta accettata
Più risposte (1)
Peter Perkins
il 16 Mag 2019
Eth, I think the more important question is how you got yourself into this corner to begin with. You say you have a table, But it looks more like you have a cell array. Probably you have a table all of whose variables are cell columns. Given that you have both text, logical, and numeric data, that's not a good position to be in. However you got there has made things much harder than they need to be.
This is the table you want:
>> t
t =
11×6 table
LastName Age Smoker Height Weight BloodPressure
_________ ___ ___________ ______ ______ _____________
<missing> NaN <undefined> NaN NaN NaN NaN
"Sanchez" 38 true 71 176 124 93
<missing> NaN <undefined> NaN NaN NaN NaN
"Johnson" 43 false 69 163 109 77
<missing> NaN <undefined> NaN NaN NaN NaN
"Li" 38 true 64 131 125 83
<missing> NaN <undefined> NaN NaN NaN NaN
"Diaz" 40 false 67 133 117 75
<missing> NaN <undefined> NaN NaN NaN NaN
"Brown" 49 true 64 119 122 80
<missing> NaN <undefined> NaN NaN NaN NaN
At that point, rmmissing or fillmissing are simple one-liners to clean up your data.
Vedere anche
Categorie
Scopri di più su Tables in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!