HOW CAN I WRITE THE CODES?

조회 수: 13 (최근 30일)
Setayesh Asadifard
Setayesh Asadifard 2021년 12월 19일
댓글: Image Analyst 2021년 12월 19일
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?

답변 (1개)

Walter Roberson
Walter Roberson 2021년 12월 19일
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
Image Analyst
Image Analyst 2021년 12월 19일
Wouldn't the whole function just be
function enKucukSayi = UcSayininMinimumunuBul1(A, B, C)
enKucukSayi = min([A, B, C]);

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by