MATLAB: How to find the largest number

counterlargest number

Hi, I have 3 numbers and I have to find the biggest one, what is the best way? This is the code:
T=200
if isempty(counter) || counter >= T
counter=0;
d1=0.1
d2=0.2
d3=0.6
else counter=counter+1
if counter>0
if d1=max([d1,d2,d3)]
...
elseif d2=max([d1,d2,d3)]
...
elseif d3=max([d1,d2,d3)]
...
end
end
end
But this code doesn't work, thank you

Best Answer

numbers = [num1 num2 num3]; % the array of numbers from which to search
maxVal = max(numbers); % the highest number