How can I extract certain rows from a CSV imported table?
Show older comments
I have imported CSV file into MATLAB
T = readtable('Historia_Rachunku.csv')
Extracted relevant part of it:
variablesByName = T(1:end,["Odbiorca","Data Księgowania","Kwota",])

And now I'd like to extract transactions belonging to single company. I tried this:
rowsByName = T(["PAYPRO S.A."],:)
But I get an error. How can I extract transactions based on their companies (ex. BILETY, PAYPRO, ZABKA) and then put them into separate tables?
Accepted Answer
More Answers (1)
Walter Roberson
on 4 Sep 2022
In order for you to be able to do that using the syntax you tried, you would have needed to have told MATLAB that table() T should have 'RowNames', with the data giving by the Odbiorca column.
However, 'RowNames' must be unique, and it is not clear that your entries are unique. Your entries are not unique to the number of characters that we can see.
What you can do is
G = findgroups(T.Odbiorca);
grouped_tables = splitapply(@(varargin) {table(varargin{:}, 'VariableNames', T.Properties.VariableNames)}, T, G);
grouped_tables is now a cell array of tables, in which each table only has entries for a single company.
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!