Delete Table Rows based of certain characters in a row
50 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jacob Child
el 17 de Oct. de 2023
Comentada: Jon
el 17 de Oct. de 2023
i imported data from a .txt file into a table that is approximately of size (96,000x26), im looking to delete rows based off of a string of characters contained in the first column of that data, then export the updated table to a .csv file
1 comentario
the cyclist
el 17 de Oct. de 2023
Can you upload the data (or a small, representative sample)? You can use the paper clip icon in the INSERT section of the toolbar. It will then be much easier to make sure our code works for your example. (For example, the syntax will depend on whether the first column is a string, or a character array.)
Respuesta aceptada
Jon
el 17 de Oct. de 2023
I think this is a simple example of what you want to do
name = {'cat','dog','fish','bear'}'
weight = [3,25,8,300]'
T = table(name,weight)
% remove rows with names that contain an a
idl = contains(T.name,'a');
T = T(~idl,:)
% Write to .csv'
writetable(T,'myfile.csv')
3 comentarios
Jon
el 17 de Oct. de 2023
So if I only wanted to keep rows where the name was "fish", I could use
name = {'cat','dog','fish','bear','fish'}'
weight = [3,25,8,300,19]'
T = table(name,weight)
% keep only rows whose name is 'fish'
idl = strcmp(T.name,'fish');
T = T(idl,:)
% Write to .csv'
writetable(T,'myfile.csv')
Jon
el 17 de Oct. de 2023
Or maybe this is what you are asking (if not please provide an example). Let's keep all the rows whose names include goose
name = {'cat','dog','goose','fish','mongoose','bear'}'
weight = [3,25,4,8,16,300]'
T = table(name,weight)
% Keep rows that contain 'goose'
idl = contains(T.name,'goose');
T = T(idl,:)
Más respuestas (0)
Ver también
Categorías
Más información sobre Environment and Settings en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!