grouping string values in matlab
조회 수: 5 (최근 30일)
이전 댓글 표시
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
채택된 답변
Guillaume
2017년 3월 20일
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
Guillaume
2017년 3월 20일
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.
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!