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

 Akzeptierte Antwort

Jan
Jan am 7 Jul. 2015
Bearbeitet: Jan am 7 Jul. 2015

0 Stimmen

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 Kommentare

thanks. The following error message appears
Undefined function 'eq' for input arguments of type 'cell' .
the data looks like
'L' [] [] [] [] []
'K' [] [] [] [] []
'N' [] [] [] [] []
.
.
.
Jan
Jan am 7 Jul. 2015
Bearbeitet: Jan am 7 Jul. 2015
So you see it is important to explain exactly, what kind of data you are talking of. See the strncmp approach.
Do you mean something like this:
Data = {'L', [], [], [], [], [], []; ...
'K', [], [], [], [], [], []}
? Please post always the Matlab code, which re-creates the array, you are talking of. Then the readers do not have to guess.
To import to matlab i used
*[T,M,D]= xlsread('data.xlsx)*
so
D= 'L', [], [], [], [], [], []; ...
'K', [], [], [], [], [], [] without the *{}*
my objective is to remove rows which contain letter K from d . Thank
alex solomon
alex solomon am 7 Jul. 2015
Thank you very much!!!
strncmp works
Abebe kebede
Abebe kebede am 8 Jul. 2015
dear Jan Simon,
i am working with similar data with a bit complex one. Since my contains o,oh and ho .I want to remove row start with oh . For that i used d(strncmp (d(:, 1), 'oh', 1), :) = []; . The problem is it removed also rows start with o. is ther a way to solve this problem. Thank you in advance.
Stephen23
Stephen23 am 8 Jul. 2015
Bearbeitet: Stephen23 am 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 am 8 Jul. 2015
Dear Stephen Cobeldick
Thank you so much. i see my mistake

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Azzi Abdelmalek
Azzi Abdelmalek am 7 Jul. 2015
Bearbeitet: Azzi Abdelmalek am 7 Jul. 2015

0 Stimmen

A(ismember(A(:,1),'K'),:)==[]

6 Kommentare

alex solomon
alex solomon am 7 Jul. 2015
Thanks! but i get the following error: Error using cell/ismember>cellismemberR2012a (line 199) Input A of class cell and input B of class char must be cell arrays of strings, unless one is a string.
my code loos like the following
[T,M,D]= xlsread('data.xlsx); D(ismember (D(:,1),'K'),:)==[];
Try
A(ismember(A(:,1),{'K'}),:)==[]
alex solomon
alex solomon am 7 Jul. 2015
thanks!
the same error message
Sorry it s
A(ismember(A(:,1),'K'),:)=[]
Jan
Jan am 7 Jul. 2015
@Azzi: There is no need for ismember. The "==" is a typo.
alex solomon
alex solomon am 7 Jul. 2015
Thanks so much!!
But still the same error message

Melden Sie sich an, um zu kommentieren.

Kategorien

Gefragt:

am 7 Jul. 2015

Bearbeitet:

am 8 Jul. 2015

Community Treasure Hunt

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

Start Hunting!

Translated by