How can I find the largest 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
댓글 수: 3
Mischa Kim
2014년 7월 2일
Do you only need the number (0.6) or do you want to know the specific variable ( d3 )?
alessandro
2014년 7월 2일
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])
채택된 답변
추가 답변 (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
Robert Cumming
2014년 7월 2일
you need to use
==
for comparison, i.e.
if d1==max([d1,d2,d3)]
etc...
카테고리
도움말 센터 및 File Exchange에서 Sparse Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!