简体   繁体   中英

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

我认为这就是你所追求的:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM