How to delete enitre row if the row contain matching string

2 views (last 30 days)
Hi, I have below cell matrix, and I want to remove(delete) entire row if column 3 or column4 contain NANA.
Input:
Item Identity PreName PostName hight weight date
AA1 Petrol 2 Raj 23 45 2018/02/09
AA1 Petrol 4 Hist 63 89 2018/02/09
AA2 Petrol NANA KLA 23 45 2018/02/09
AA2 Petrol BAN KAH 71 67 2018/02/09
SAA Gas TAH Forst 9 34 2018/02/09
SA4 Gas Lul NANA 53 95.3 2018/02/09
SA4 Tele JAYK YAHH 2.9 11.9 2018/02/09
SH7 Tele NANA NANA 15.3 3.3 2018/02/09
SP2 Tele FAG 8 123 100 2018/02/09
SP2 Tele 3 18 123 100 2018/02/09
Output:
Item Identity PreName PostName hight weight date
AA1 Petrol 2 Raj 23 45 2018/02/09
AA1 Petrol 4 Hist 63 89 2018/02/09
AA2 Petrol BAN KAH 71 67 2018/02/09
SAA Gas TAH Forst 9 34 2018/02/09
SA4 Tele JAYK YAHH 2.9 11.9 2018/02/09
SP2 Tele FAG 8 123 100 2018/02/09
SP2 Tele 3 18 123 100 2018/02/09

Accepted Answer

Kai Domhardt
Kai Domhardt on 9 Feb 2018
Edited: Kai Domhardt on 9 Feb 2018
Quick answer:
to_delete = (strcmp(data(:,3),'NANA') | strcmp(data(:,4),'NANA'));
data(to_delete,:) = [];
If you are interested in performance this might be interesting.
  1 Comment
Kanakaiah Jakkula
Kanakaiah Jakkula on 10 Feb 2018
Sir, I use this function, but its too slower, any other function? I even use ismember. Looking for any other function to enhance execution time.

Sign in to comment.

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!