Hi, I have this table
0 0
0 0
0,0100000000000000 0
0,0100000000000000 1
0,0100000000000000 2
0,0200000000000000 0
0,0200000000000000 1
0,0200000000000000 2
but the table that I want is this one
0 0
0.01 2
0.02 2
the second column is the highest value of each number (0 0.01 0.02)
if someone can help me I would really appreciate because I am a little bit stuck in this problem I do not know even how to start to solve it
Thanks in advance for your time
Luca

 採用された回答

Andrei Bobrov
Andrei Bobrov 2017 年 6 月 18 日
編集済み: Andrei Bobrov 2017 年 6 月 18 日

0 投票

A=[0 0
0 0
0.0100000000000000 0
0.0100000000000000 1
0.0100000000000000 2
0.0200000000000000 0
0.0200000000000000 1
0.0200000000000000 2];
[g,ii] = findgroups(A(:,1));
out = [ii,splitapply(@max,A(:,2),g)];
or
[ii,~,g] = unique(A(:,1));
out = [ii,accumarray(g,A(:,2),[],@max)];

3 件のコメント

Luca cadalo
Luca cadalo 2017 年 6 月 18 日
it does not work well because I am working with tables :(
Andrei Bobrov
Andrei Bobrov 2017 年 6 月 19 日
Please attach your tables as mat-file.
Andrei Bobrov
Andrei Bobrov 2017 年 6 月 19 日
編集済み: Andrei Bobrov 2017 年 6 月 19 日
A=[0 0
0 0
0.0100000000000000 0
0.0100000000000000 1
0.0100000000000000 2
0.0200000000000000 0
0.0200000000000000 1
0.0200000000000000 2];
A= num2cell(A,1);
T = table(A{:},'va',{'x','y'});
%solution
T_out = varfun(@max,T,'group','x');

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeTables についてさらに検索

質問済み:

2017 年 6 月 18 日

編集済み:

2017 年 6 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by