Remove unwanted text/punctuation from table

11 vues (au cours des 30 derniers jours)
SM
SM le 28 Juin 2021
Commenté : SM le 28 Juin 2021
There is probably a simple way to do this but for whatever reason, I seem to be struggling a little. I have a table that is nxn in size. One column in this table has cells that contain text within quotation marks along with cells that simply have quotation marks. I'm trying to extract the rows that have cells from that column containing text within the quotation marks. In essence, I want to remove rows that have only quotes. For example, my table looks like this:
1 2 3 ""
4 5 6 ""
7 8 9 "yes"
10 11 12 "no"
13 14 15 "ok"
In the example above, what I want is to find the indices of the rows that contain cells with words in the last column- I want to filter out the rows that simply have ' "" ' in the last column as shown. I've tried the 'find' and 'contains' commands but trying to specify ' "" ' as the object to find selects every row since even the words in the last column in the example above are within quotes. Can someone please offer some advice? For reference, I'm using MATLAB R2019b. Thanks!

Réponse acceptée

Cris LaPierre
Cris LaPierre le 28 Juin 2021
Modifié(e) : Cris LaPierre le 28 Juin 2021
Standardize your missing values to MATLAB default values, then use rmmissing to remove any row that contains a missing value.
% Create your table
var1 = [1 4 7 10 13]';
var2 = [3 5 8 11 14]';
var3 = ["" "" "yes" "no" "ok"]';
T = table(var1,var2,var3)
T = 5×3 table
var1 var2 var3 ____ ____ _____ 1 3 "" 4 5 "" 7 8 "yes" 10 11 "no" 13 14 "ok"
% Standardize missing values
T.var3 = standardizeMissing(T.var3,"")
T = 5×3 table
var1 var2 var3 ____ ____ _________ 1 3 <missing> 4 5 <missing> 7 8 "yes" 10 11 "no" 13 14 "ok"
% remove any row with a missing value
Tnew = rmmissing(T,1)
Tnew = 3×3 table
var1 var2 var3 ____ ____ _____ 7 8 "yes" 10 11 "no" 13 14 "ok"
  1 commentaire
SM
SM le 28 Juin 2021
Thanks, Cris! That did it for me. Appreciate the help!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Tables dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by