deleting all rows from a table that contain a string
11 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
更多回答(1 个)
Peter Perkins
2019-5-16
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.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!