How do extract rows containting certain strings from a table to make a new table?
2 views (last 30 days)
Show older comments
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!
0 Comments
Accepted Answer
Jon
on 10 Feb 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 Comment
Stephen23
on 10 Feb 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:
More Answers (0)
See Also
Categories
Find more on Tables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!