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

Sim*_*ity -3 matlab max matrix reshape

假设我们有以下矩阵:

2 5
5 3 
6 3
6 4 
Run Code Online (Sandbox Code Playgroud)

我想要做的是:

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
Run Code Online (Sandbox Code Playgroud)

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

reshape(I,2,2)
Run Code Online (Sandbox Code Playgroud)

一开始听起来微不足道.我尝试在矩阵上执行上面的步骤165536x2,但最后得到一个131072x1矩阵,我原本计划reshape进入256x256矩阵,因为我认为我将65536x1在第一步结束矩阵.

怎么可能出错?

谢谢.

Sha*_*hai 5

在Matlab中 - 矢量化!

mx = max( u, [], 2 ); % find max along rows of u
reshape( mx, 256, 256 ); 
Run Code Online (Sandbox Code Playgroud)