Remove unwanted text/punctuation from table

9 ビュー (過去 30 日間)
SM
SM 2021 年 6 月 28 日
コメント済み: SM 2021 年 6 月 28 日
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!

採用された回答

Cris LaPierre
Cris LaPierre 2021 年 6 月 28 日
編集済み: Cris LaPierre 2021 年 6 月 28 日
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 件のコメント
SM
SM 2021 年 6 月 28 日
Thanks, Cris! That did it for me. Appreciate the help!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by