Removing rows of table based on logical array
32 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Nicholas
el 1 de Jul. de 2023
Editada: Peter Perkins
el 17 de Jul. de 2023
Hello, I have an imported table of data that is 122 x 11.
I have identified an xdata and ydata I want to use, and have named them such.
ydata comes from column 7 of my table.
I am singling out the heighest 10 values in this column by using
topTenData = maxk(ydata, 10)
that identified a minimum value of 1.01, and I'm uninterested in any data below that value.
I am attempting to get rid of all rows that are smaller than this using (remember column 7 is ydata):
TT = data(:,7) < 1.01
data(TT,:) = []
What I expect to happen is anywhere in which TT returns true, the row will be removed.
Instead, I get an error stating:" A table row subscript must be a numeric array containing real positive integers, a logical array, a character vector, a string-array, a cell array of character vectors, or a pattern scalar."
Does this mean that if my raw data rows have a multitude of different types of data within each column, it is not possible to delete the rows this way? If so, can I get some guidance on a better method? Thanks!
0 comentarios
Respuesta aceptada
Voss
el 1 de Jul. de 2023
I think the problem is with this line:
TT = data(:,7) < 1.01
With data being a table, I get the error, "Undefined operator '<' for input arguments of type 'table'."
Instead of using parentheses ( ) you should use curly braces { } to access the contents of a table, as in:
TT = data{:,7} < 1.01
Then that line will run and TT will be a logical vector you can use to delete rows from the table as you intend.
Here's a simple complete example to illustrate:
% a table with two columns:
data = table(randi(10,10,1),randi(10,10,1))
% a logical vector saying whether the data in column 2 is less than 4.
% Note: use curly braces {} to access the contents of a table.
TT = data{:,2} < 4
% remove those rows from the table:
data(TT,:) = []
2 comentarios
Peter Perkins
el 17 de Jul. de 2023
Editada: Peter Perkins
el 17 de Jul. de 2023
Voss is correct up to a point, but there is some late-breaking R2023a news that changes the story. Please see my comment in another thread:
Más respuestas (0)
Ver también
Categorías
Más información sobre Data Type Identification en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!