How can I find the largest number
45 次查看(过去 30 天)
显示 更早的评论
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
3 个评论
Roberto Calandra
2014-7-2
Remember that with d1=max([d1,d2,d3]) you are assigning a variable to d1but what you want is checking for equality as in d1==max([d1,d2,d3])
采纳的回答
Elias Gule
2014-7-2
numbers = [num1 num2 num3]; % the array of numbers from which to search
maxVal = max(numbers); % the highest number
0 个评论
更多回答(2 个)
Roberto Calandra
2014-7-2
Something like this?
switch max([d1,d2,d3])
case {d1}
V=V1
case {d2}
V=V2
case {d3}
V=V3
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multidimensional Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!