HOW CAN I WRITE THE CODES?

14 visualizaciones (últimos 30 días)
Setayesh Asadifard
Setayesh Asadifard el 19 de Dic. de 2021
Comentada: Image Analyst el 19 de Dic. de 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?

Respuestas (1)

Walter Roberson
Walter Roberson el 19 de Dic. de 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 comentario
Image Analyst
Image Analyst el 19 de Dic. de 2021
Wouldn't the whole function just be
function enKucukSayi = UcSayininMinimumunuBul1(A, B, C)
enKucukSayi = min([A, B, C]);

Iniciar sesión para comentar.

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by