amax = a .* bsxfun(@eq, a, max(a,[],2));
set rows to zero except maximum value
Question
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.
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow