필터 지우기
필터 지우기

Removing rows from table based on content

조회 수: 6 (최근 30일)
Jakub Steiner
Jakub Steiner 2021년 2월 7일
댓글: Jakub Steiner 2021년 2월 7일
Hi,
I got some data with "false" values that I need to remove
The data looks as following...
I need to remove all rows that include the letter "x". The fourth column sometimes consists only of the letter "x", sometimes it consists of "x" and other values as seen on the picture.
I am loading the data usinf following code
filename = 'Sample.txt';
fileID = fopen(filename);
opts = detectImportOptions(filename);
opts.VariableTypes{1} = 'string';
opts.VariableTypes{4} = 'string';
M = readtable(filename,opts);
fclose(fileID);
All help is welcomed and appreciated.

채택된 답변

KALYAN ACHARJYA
KALYAN ACHARJYA 2021년 2월 7일
편집: KALYAN ACHARJYA 2021년 2월 7일
If you are wish to check the single string with x only, as in the rows 6 and 7, then you can accomplish it easily. In that case it avoid the removal of row 5, where x is also there within the string ( with Gap consideation).
id=find(strcmp('x',M.Var4));
M(id,:) = []
Result:
M =
10×4 table
Var1 Var2 Var3 Var4
_______________ ____ __________ ______________________________
"1598607723000" 4 6.5162e+14 "9049F00430000764B1BD4046DCEA"
"1598607723000" 12 6.5162e+14 "8D06A10E99158B12D00427C73A6C"
"1598607723000" 14 6.5162e+14 "8D06A10E99158B12D00427C73A6C"
"1598607723000" 16 6.5162e+14 "8D06A10E99158B12D00427C73A6C"
"1598607723000" 10 6.5162e+14 "8D06A10E99158B12D00427C73A6C"
"1598607723000" 12 6.5162e+14 "x 5D4BCCB982A069"
"1598607723000" 14 6.5162e+14 "8D48C12B5811F16DD1085E938F4F"
"1598607723000" 12 6.5162e+14 "8D48C12B5811F16DD1085E938F4F"
"1598607723000" 4 6.5162e+14 "8D48C12B5811F16DD1085E938F4F"
"1598607723000" 3 6.5162e+14 "8D48C12B5811F16DD1085E938F4F"
But If you wish to remove the 5 rows also, within the strings x is there, not single 'x' string, in that case I have used loop, may be it can be avoided.
for i=1:length(M.Var4)
id(i)=max(strcmp('x',split(M.Var4(i))))
end
M(id,:) = []
Result:
M =
9×4 table
Var1 Var2 Var3 Var4
_______________ ____ __________ ______________________________
"1598607723000" 4 6.5162e+14 "9049F00430000764B1BD4046DCEA"
"1598607723000" 12 6.5162e+14 "8D06A10E99158B12D00427C73A6C"
"1598607723000" 14 6.5162e+14 "8D06A10E99158B12D00427C73A6C"
"1598607723000" 16 6.5162e+14 "8D06A10E99158B12D00427C73A6C"
"1598607723000" 10 6.5162e+14 "8D06A10E99158B12D00427C73A6C"
"1598607723000" 14 6.5162e+14 "8D48C12B5811F16DD1085E938F4F"
"1598607723000" 12 6.5162e+14 "8D48C12B5811F16DD1085E938F4F"
"1598607723000" 4 6.5162e+14 "8D48C12B5811F16DD1085E938F4F"
"1598607723000" 3 6.5162e+14 "8D48C12B5811F16DD1085E938F4F"
  댓글 수: 2
KALYAN ACHARJYA
KALYAN ACHARJYA 2021년 2월 7일
Later (more free time), I will update the 2nd one without loop, if any.
Jakub Steiner
Jakub Steiner 2021년 2월 7일
Thanks a lot sir, you made my day much better.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by