필터 지우기
필터 지우기

grouping string values in matlab

조회 수: 5 (최근 30일)
Ananya Malik
Ananya Malik 2017년 3월 20일
댓글: Guillaume 2017년 3월 20일
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

채택된 답변

Guillaume
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
Ananya Malik
Ananya Malik 2017년 3월 20일
Hi @Guillaume. Thank you for the answer. Works perfectly for given data . However I have a large data set with 227k entries and 1083 different people. 'readtable' has a limit of 65536 entries. Thank you for your patience.
Guillaume
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개)

ES
ES 2017년 3월 20일
read using
xlsread
sort column 2 using
sort

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by