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

 Respuesta aceptada

Jan
Jan el 7 de Jul. de 2015
Editada: Jan el 7 de Jul. de 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 comentarios

thanks. The following error message appears
Undefined function 'eq' for input arguments of type 'cell' .
the data looks like
'L' [] [] [] [] []
'K' [] [] [] [] []
'N' [] [] [] [] []
.
.
.
Jan
Jan el 7 de Jul. de 2015
Editada: Jan el 7 de Jul. de 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 el 7 de Jul. de 2015
Thank you very much!!!
strncmp works
Abebe kebede
Abebe kebede el 8 de Jul. de 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 el 8 de Jul. de 2015
Editada: Stephen23 el 8 de Jul. de 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 el 8 de Jul. de 2015
Dear Stephen Cobeldick
Thank you so much. i see my mistake

Iniciar sesión para comentar.

Más respuestas (1)

Azzi Abdelmalek
Azzi Abdelmalek el 7 de Jul. de 2015
Editada: Azzi Abdelmalek el 7 de Jul. de 2015
A(ismember(A(:,1),'K'),:)==[]

6 comentarios

alex solomon
alex solomon el 7 de Jul. de 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 el 7 de Jul. de 2015
thanks!
the same error message
Sorry it s
A(ismember(A(:,1),'K'),:)=[]
Jan
Jan el 7 de Jul. de 2015
@Azzi: There is no need for ismember. The "==" is a typo.
alex solomon
alex solomon el 7 de Jul. de 2015
Thanks so much!!
But still the same error message

Iniciar sesión para comentar.

Categorías

Más información sobre Data Type Conversion en Centro de ayuda y File Exchange.

Preguntada:

el 7 de Jul. de 2015

Editada:

el 8 de Jul. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by