user25004
user25004

Reputation: 2088

How to eliminate this loop from my Matlab code?

My goal is to change an order three matrix, to an order two matrix simply (perhaps with one line of code) 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

Upvotes: 4

Views: 65

Answers (1)

Marcin
Marcin

Reputation: 239005

I think this is what you are after:

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

Upvotes: 4

Related Questions