How can I eliminate this loop from my Matlab code?

My goal is to reverse the order of the three matrices, by an order of magnitude two matrices just (with one line of code perhaps) Any idea?

A = rand(256, 256, 3);
B = zeros(256, 256);


for i = 1: size(A, 1)
    for j = 1 : size(A, 2)
        B(i,j) = max(A(i,j, :));
    end
end

      

+3


source to share


1 answer


I think this is what you need:



B = max(A, [], 3);

      

+4


source







All Articles