フィルターのクリア

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 Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by