フィルターのクリア

How to find max value of three varibles using if,else,end.

13 ビュー (過去 30 日間)
Giuseppe
Giuseppe 2014 年 3 月 12 日
回答済み: Vallambotla 2022 年 11 月 28 日
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

採用された回答

Chris C
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 件のコメント
Giuseppe
Giuseppe 2014 年 3 月 14 日
thank you very much
Ram Charan
Ram Charan 2021 年 2 月 12 日
thank you so much

サインインしてコメントする。

その他の回答 (2 件)

siva naga sai babu
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

Vallambotla
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

カテゴリ

Help Center および File ExchangeArgument Definitions についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by