MATLAB找到最大结构 [英] MATLAB finding max. of a struct

查看:85
本文介绍了MATLAB找到最大结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试查找结构的最大值,但max([tracks(:).matrix])不起作用.它给了我以下错误:使用horzcat时出错 CAT参数的尺寸不一致."有想法吗?

I am trying to find max value of a struct but max([tracks(:).matrix]) does not work. It gives me the following error: "Error using horzcat CAT arguments dimensions are not consistent." Do you have an idea?

这是我的结构的样子:

tracks = 

1x110470 struct array with fields:
    nPoints
    matrix

tracks.matrix包含3D点.例如,这里是

tracks.matrix includes 3D points. For example here is

tracks(1,2).matrix:

33.727467   96.522331   27.964357
31.765503   95.983849   28.984663
30.677082   95.989578   29

推荐答案

您可以使用数组fun,然后再使用另一个max来做到这一点:

You can use array fun, followed by another max to do this:

s.x = [1 3 4];
s(2).x = [9 8];
s(3).x = [1];

maxVals = arrayfun(@(struct)max(struct.x(:)),s);

maxMaxVals = max(maxVals(:));

或者,如果要在MAX之后保留.x的大小:

Or, if you want to retain the size of .x after MAX:

s.x = [1 3 4];
s(2).x = [9 8 3];
s(3).x = [1 2 2; 3 2 3];

maxVals = arrayfun(@(struct)max(struct.x,[],1),s,'uniformoutput',false);

maxMaxVals = max(cat(1,maxVals{:}))

或者,如果您知道一切都是n x 3

Or, if you know everything is n x 3

s.x = [1 3 4];
s(2).x = [9 8 3];
s(3).x = [1 2 2; 3 2 3];
matrix = cat(1,s.x)
maxVals = max(matrix)

这篇关于MATLAB找到最大结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆