假设我在MATLAB中有一个这样的表:
Location String Number
1 a 26
1 b 361
2 c 28
2 a 45
3 a 78
4 b 82
我想创建一个只返回3行的脚本,其中包括每个字符串的最大Number。因此,在这种情况下,返回的表将如下所示:
Location String Number
3 a 78
1 b 361
2 c 28
我想要处理的实际表要大得多,尽管我这样写是为了简单。如何处理这个任务?
2条答案
按热度按时间bf1o4zei1#
您可以使用
splitapply
,每行有一个id
。请查看评论了解详细信息...或者只是一个简单的循环。这个循环只在
String
的唯一值上,所以应该很快。xu3bshqb2#
找到每个字符串的最大值我的想法是。
为所有字符串创建一个vector,并只包含一次。类似于:
strs=['a','b','c'];
然后创建一个vector来存储每个字符串的最大值:
现在创建一个循环,将当前的max_value与当前值进行比较,并替换if
current_value>max_value
: