How to delete a row with specific letter
4 views (last 30 days)
Show older comments
i have a mixed data (1000 by 6) at which the first column contains letter like N, K , L and O. How can i delete a rows which contain letter 'K'. Thanks
0 Comments
Accepted Answer
Jan
on 7 Jul 2015
Edited: Jan
on 7 Jul 2015
If the "(1000 by 6)" data are a CHAR Matrix:
A(A(:,1)=='K') = [];
But "mixed data" could mean, that you have a cell array. So perhaps you want:
A(strncmp(A(:, 1), 'K', 1), :) = [];
7 Comments
Stephen23
on 8 Jul 2015
Edited: Stephen23
on 8 Jul 2015
@Abebe kebede: read the documentation for strncmp. It checks as many characters as the last argument tells it to, which is your case is one, so both 'oh' and 'o' match this. Change the value to two, and you will find that it works:
strncmp(d(:, 1), 'oh', 2)
More Answers (1)
Azzi Abdelmalek
on 7 Jul 2015
Edited: Azzi Abdelmalek
on 7 Jul 2015
A(ismember(A(:,1),'K'),:)==[]
6 Comments
See Also
Categories
Find more on Logical 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!