Using accumarray with nested inline function
4 次查看(过去 30 天)
显示 更早的评论
Hi
I have below data and would like to use accumarray to perform calculation with inline functions
locOut = @(x) matches( x,"Gross", 'Ignorecase',true); % identifying rows for Gross data
NetCalc= @( flag, loss) ( loss( locOut(flag)) - sum( loss(~locOut(flag))));
Calculating Net Loss = Gross - sum( other rows)
[ uniqLayer,~,JGrp] = unique( LayerId));
final = accumarray( JGrp, loss, [], @PRA_GetNetLoss( flag, loss) ); % Not working
flag = {'xIGW','Gross','QS','BH','Fac','QS2', 'Gross','BH'}';
loss = [1 2 3 6 5 6 10 20];
layerID = [ 111 111 111 111 111 111 222 222]
0 个评论
采纳的回答
Steven Lord
2021-5-25
@PRA_GetNetLoss( flag, loss)
This is not syntacticallly valid in MATLAB. Make this an anonymous function like you did with locOut and NetCalc.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Function Creation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!