这个问题已经有一个答案在这里:

我有一个4D列测量MATLAB。每个维代表不同的参数,用于测量。我想找到的最大值和最小值和指数(即哪些参数)。

什么是最好的方式来做到这一点?我想我可以带最大的max max在各个层面,但这似乎是一个暂且。

有帮助吗?

解决方案

简单的例子:

%# random 4 d array with different size in each dim
A = rand([3,3,3,5]);

%# finds the max of A and its position, when A is viewed as a 1D array
[max_val, position] = max(A(:)); 

%#transform the index in the 1D view to 4 indices, given the size of A
[i,j,k,l] = ind2sub(size(A),position);

发现的最小的是左作为一个运动:).

以下评论:如果你不知道数量的尺寸您阵列,因此不能写"[i,j,k,l] ="部分中,使用这种技巧:

indices = cell(1,length(size(A)));

[indices{:}] = ind2sub(size(A),position);

其他提示

对两个维阵列,说,我 你可以使用的最低/最高函数的两倍。n次n维阵列。例如: a=[2 3 4; 5 6 7; -2 7 87; 911 7 34];

for minimum:  min(min(a,[],1))
             ->  the answer will be -2. 

你可以把的尺寸参数在最大/最小到2。作为这个叫功能两次,第二次在最低/最大元素的矢量的尺寸u选择。

同样,你可以做的 (max(max(a,[],1)) 找出最大。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top