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 CenterFile Exchange에서 Tables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by