MATLAB 发现最大值。结构的

标签 matlab octave

我正在尝试查找结构的最大值,但 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/

相关文章:

matlab - 为什么 MatLab 要把实数复杂化?

file-io - 在 Octave 中保存和加载矩阵的最快文件格式?

matlab - Octave 中的函数句柄格式

matlab - 嵌套函数在 Octave/Matlab 中看不到局部变量

javascript - 将用 Octave 编写的 K-means 转换为 Tensorflow.js

matlab - MATLAB 中的图像卷积 - conv 为什么比我的手写版本快 360 倍?

Matlab:如何将矩阵转换为 Toeplitz 矩阵

matlab - 将散点图转换为面积图

matlab - accumarray 输出的解释

java - 如何抑制 Octave io 包加载警告 : "OpenJDK 64-Bit Server VM warning: Archived . .. java.system.class.loader 属性