How to delete a row with specific letter

4 views (last 30 days)
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

Accepted Answer

Jan
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
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)
Abebe kebede
Abebe kebede on 8 Jul 2015
Dear Stephen Cobeldick
Thank you so much. i see my mistake

Sign in to comment.

More Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 7 Jul 2015
Edited: Azzi Abdelmalek on 7 Jul 2015
A(ismember(A(:,1),'K'),:)==[]
  6 Comments
Jan
Jan on 7 Jul 2015
@Azzi: There is no need for ismember. The "==" is a typo.
alex solomon
alex solomon on 7 Jul 2015
Thanks so much!!
But still the same error message

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!