查找每行的最大值并重新整形矩阵

时间:2013-06-18 13:38:17

标签: matlab matrix max reshape

假设我们有以下矩阵:

2 5
5 3 
6 3
6 4 

我要做的是:

1-查找每行的最大值 对于这部分,我认为我们可以做到以下几点?

[r,c] = size(u);
for i=1:c
for j=1:r
index=1;
for i=1:c
    for j=1:r
       [value,position]=max(u(j,:)); 
       membershipMatrix(index)=value; 
       index=index+1;
    end
end

2-然后,我想将上述矩阵重塑为2x2矩阵。 我想我们可以在这做以下几点吗?

reshape(I,2,2)

一开始听起来微不足道。我尝试在65536x2矩阵上执行上面的步骤 1 ,但最终得到了131072x1矩阵,我最初计划reshape进入256x256 }}矩阵,因为我认为第一步最终会得到一个65536x1矩阵。

可能出现什么问题?

感谢。

1 个答案:

答案 0 :(得分:5)

在Matlab中 - vectorize!

mx = max( u, [], 2 ); % find max along rows of u
reshape( mx, 256, 256 ); 
相关问题