How to find max value of three varibles using if,else,end.
19 次查看(过去 30 天)
显示 更早的评论
The variables are:
a=20
b=10
c=30
How do i find the max without using built in functions.
I believe it is
if a>b && a>c
disp(a)
elseif b>a && b>c
disp(b)
else
disp(c)
end
0 个评论
采纳的回答
Chris C
2014-3-12
编辑:Chris C
2014-3-12
Give this code a shot. You would be able to make the variable "data" listed here as a vector of whatever data you like and this should still work. If you had a matrix instead of a vector, however, you would need to loop around both the rows and columns.
a = 20;
b = 10;
c = 30;
data = [a,b,c];
largest = data(1);
for i = 1:length(data)
if data(i) > largest;
largest = data(i);
end
end
更多回答(2 个)
siva naga sai babu
2021-2-17
a = 20;
b = 10;
c = 30;
data = [a,b,c];
largest = data(1);
for i = 1:length(data)
if data(i) > largest;
largest = data(i);
end
end
0 个评论
Vallambotla
2022-11-28
a = 20;
b = 10;
c = 30;
data = [a,b,c];
largest = data(1);
for i = 1:length(data)
if data(i) > largest;
largest = data(i);
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Vibration Analysis 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!