HOW CAN I WRITE THE CODES?

13 views (last 30 days)
Setayesh Asadifard
Setayesh Asadifard on 19 Dec 2021
Commented: Image Analyst on 19 Dec 2021
Write a MATLAB function that finds and returns the smallest of the 3 numbers it takes as a parameter, into the function m-file named UcSayininMinimunuBul.m
THIS IS MY PROBLEM
I TRIED ALOT TO WRITE THE CODES OF THIS PROGRAM BUT I HAD SOME MISTAKES EVERYTIME
CAN ANYONE WRITE THE CODES FOR ME HERE?

Answers (1)

Walter Roberson
Walter Roberson on 19 Dec 2021
Using your code from before:
A=1;
B=2;
C=3;
enKucukSayi=UcSayininMinimumunuBul1(A,B,C);
Store those lines in the file test_SayininMin.m
Store the below lines in UcSayininMinimumunuBul1.m
function enKucukSayi=UcSayininMinimumunuBul1(A,B,C)
if A<B && A<C
enKucukSayi=A;
elseif B<A && B<C
enKucukSayi=B;
else
enKucukSayi=C;
end
end
And to test, run the file test_SayininMin
Your code does have a little bit of a problem: it does not properly handle the case where two of the values are equal.
  1 Comment
Image Analyst
Image Analyst on 19 Dec 2021
Wouldn't the whole function just be
function enKucukSayi = UcSayininMinimumunuBul1(A, B, C)
enKucukSayi = min([A, B, C]);

Sign in to comment.

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!