Вопрос

Hopefully someone can help me with the following MATLAB problem. I have a matrix, for example:

a = [ 1 2 3 ; 4 6 5 ; 9 8 7 ]

I want to create a matrix with only the maximum of each row, and the rest set to zero. So in this case:

amax = [ 0 0 3 ; 0 6 0 ; 9 0 0 ]

I figure this is not so dificult haha but I can't figure it out! Thanks in advance for the help.

Это было полезно?

Решение

amax = a .* bsxfun(@eq, a, max(a,[],2));
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top