work with matrix of words and number

1 回表示 (過去 30 日間)
Madan Ghimire
Madan Ghimire 2019 年 8 月 15 日
コメント済み: Madan Ghimire 2019 年 8 月 16 日
Hey guys,
I work with matrix that have words on one column and their corresponding value on the other column as such
'Apple' 13.6000000000000
'Apple' 7.23200000000000
'Apple' 6.73600000000000
'Ball' 1.34900000000000
'Cat' 1.71600000000000
'Dog' 2.66100000000000
'Cat' 0.771000000000000
and the order of these words is random. I need to calculate the mean for individual words. I appretiate any help.
thanks

採用された回答

Andrei Bobrov
Andrei Bobrov 2019 年 8 月 16 日
T = readtable('txtfile.txt')
T_out = varfun(@mean,T,'GroupingVariables','Var1');
  1 件のコメント
Madan Ghimire
Madan Ghimire 2019 年 8 月 16 日
Thanks. Works perfect for me

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2019 年 8 月 15 日
[unique_names, ~, idx] = unique(YourCell(:,1));
mean_per_word = accumarray(idx, cell2mat(YourCell(:,2)), [], @mean);
output = [unique_names, num2cell(mean_per_word)];

カテゴリ

Help Center および File ExchangeData Types についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by