getting maximum value of each row of a matrix that has integers elements and INF

suppose
mat =
2 9 11 Inf
1 2 Inf Inf
how do i get the maximum of each row such that it is not the inf e.g.: i want to get mat(1,:)=11 and mat(2,:)=2
i tried using the for loop it is as follow (but it doesn't work :( )
[a,b]=size(mat);
for row=1:a
for column=1:b
if(mat(row,column)~=inf && mat(row,column)==max(mat(row,:))
maxvalue_notinfinity=max(mat(row,:));
end
end
end
i know this is wrong but i don't know how to write the condition that i am looking for HELP PLEASE :)

Answers (1)

One simple way would be to replace the Inf by -Inf before calling max:
matdup = mat;
matdup(isinf(mat)) = -Inf;
maxvalue_notinf = max(matdup, [], 2);

Categories

Tags

Asked:

on 17 Oct 2014

Answered:

on 17 Oct 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!