HOW CAN I WRITE THE CODES?

6 vues (au cours des 30 derniers jours)
Setayesh Asadifard
Setayesh Asadifard le 19 Déc 2021
Commenté : Image Analyst le 19 Déc 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?

Réponses (1)

Walter Roberson
Walter Roberson le 19 Déc 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 commentaire
Image Analyst
Image Analyst le 19 Déc 2021
Wouldn't the whole function just be
function enKucukSayi = UcSayininMinimumunuBul1(A, B, C)
enKucukSayi = min([A, B, C]);

Connectez-vous pour commenter.

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by