How do extract rows containting certain strings from a table to make a new table?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
new2matlab
am 10 Feb. 2020
Kommentiert: Stephen23
am 10 Feb. 2020
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 Kommentare
Akzeptierte Antwort
Jon
am 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 Kommentar
Stephen23
am 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:
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Tables finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!