How do extract rows containting certain strings from a table to make a new table?

18 vues (au cours des 30 derniers jours)
I have a large input table that has columns containing letters and numbers. I am looking for a way to scan the table to find which rows contain certain words such as "NaN" or "CORRECT" and sort each of those into their own new table. Any advice is appreciated!

Réponse acceptée

Jon
Jon le 10 Fév 2020
Suppose you had a table called myTable with a column (variable name) named quality with certain words such as 'NaN' 'CORRECT' etc.
You could find the indices of the rows in the table that had for example the word 'CORRECT' using
idxCorrect = strcmpi(myTable.quality,'correct'); % use strcmpi so it will be case insensitive assuming that is what you want
Now make a new table with just those rows
newTable = myTable(idxCorrect,:)
Note though in general it is better not to start making lots of little tables unless you really need to.
Instead if possible just leave the data in the one big table just use your searching as above to find rows with a certain criteria, as needed. Depends on what you are trying to do though. Maybe makes sense in your situation to form some smaller tables.
  1 commentaire
Stephen23
Stephen23 le 10 Fév 2020
"...in general it is better not to start making lots of little tables unless you really need to."
Indeed, a much better approach is usually like this:

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Tables dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by