我正在尝试查找结构的最大值,但 max([tracks(:).matrix])
不起作用。它给了我以下错误:“使用 horzcat 时出错
CAT 参数维度不一致。”你有想法吗?
这是我的结构的样子:
tracks =
1x110470 struct array with fields:
nPoints
matrix
tracks.matrix 包含 3D 点。比如这里是
tracks(1,2).matrix:
33.727467 96.522331 27.964357
31.765503 95.983849 28.984663
30.677082 95.989578 29
最佳答案
您可以使用数组 fun,然后使用另一个 max 来执行此操作:
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 的大小:
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
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 发现最大值。结构的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13575523/