Index from accumarray with max/min

前端 未结 2 871
甜味超标
甜味超标 2021-01-21 04:32

I have a vector and a cell array (with repeating strings) with the same size. The cell array defines the groups. I want to find min/max values in the vector for each group.

2条回答
  •  臣服心动
    2021-01-21 05:16

    When faced with a similar problem*, I came up with this solution:

    • define the following function (in a .m file)

         function i=argmax(x)
         [~,i]=max(x);
         end
      
    • then you can find the max locations as

         gridx = accumarray(grnum,grnum,[],@(i)i(argmax(value(i))) );
      
    • and the max values as

         grvalue = value(gridx);
      

    (*if I understand your problem correctly)

提交回复
热议问题