grouping string values in matlab
3 views (last 30 days)
Show older comments
I have 3 columns. 1st column is a numeric (1,2,3....) denoting person number. 2nd column states the day of week(sun-sat). 3rd column consists location names (paris,london,italy...). I want to group the 3rd column based on 2nd column for a particular person, i.e. all the locations a particular person may visit on a particular day. Attached is a sample file containing both input and the required output. any help will be greatly appreciated
0 Comments
Accepted Answer
Guillaume
on 20 Mar 2017
t = readtable('help.xls', 'Range', 'A3:C17', 'ReadVariableNames', false);
t.Properties.VariableNames = {'Person', 'Weekday', 'Location'};
%Note: the current format of your excel sheet is not practical.
%Just the data with a column header would mean that the above two lines can be replaced with:
%t = readtable('help.xls');
[groups, groupedtable] = findgroups(t(:, [1 2]));
groupedtable.Locations = splitapply(@(locs) {strjoin(locs, ',')}, t.Location, groups)
2 Comments
Guillaume
on 20 Mar 2017
No, readtable does not have a limit (other than the one imposed by Excel itself which is currently 1,048,576).
However, the .xls format does have a limit of 65,536 rows. This has nothing to do with readtable but is a restriction imposed by excel. The simplest way to fix this is to use the .xlsx format.
More Answers (1)
See Also
Categories
Find more on Spreadsheets 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!