MATLAB 中的 GROUP BY
我想做 SQL 的 GROUP BY 在 MATLAB 中所做的事情。例如,
M = [
1, 5;
2、5;
3, 5;
1, 6;
2, 6;
1,7 ]
SQL:从 M(c1, c2) GROUP BY 2 中选择 MAX(c1), c2
结果 = [
3, 5;
2, 6;
1, 7]
我怎样才能在 Matlab 中做到这一点?
I want to do what SQL's GROUP BY does in MATLAB. For example,
M = [
1, 5;
2, 5;
3, 5;
1, 6;
2, 6;
1,7 ]
SQL: SELECT MAX(c1), c2 FROM M(c1, c2) GROUP BY 2
Result = [
3, 5;
2, 6;
1, 7]
How can I do this in Matlab?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
统计工具箱中的
grpstats
可以做到这一点:grpstats
in the Statistics Toolbox can do this:如果您不介意进行一些预处理来获取顺序(或者如果第一列很好地从 1 到
n
构建),您可以这样做:这将给出:
或者在您的情况下:
注意顺序。例如,第二个数字将对应于
M(:,1) == 2
If you don't mind doing some preprocessing to get the order (or if the first column is nicely built from 1 to
n
), you can do it like this:This will give:
Or in your case:
Note the order. The second number for example, will correspond to
M(:,1) == 2
我认为有一个简单的解决方案。
这是我在 Matlab 上测试的结果,它有效:
I think there is a simple solution to this.
Here is what I tested on Matlab and it worked: