HOW CAN I WRITE THE CODES?
조회 수: 13 (최근 30일)
이전 댓글 표시
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
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
2021년 12월 19일
Wouldn't the whole function just be
function enKucukSayi = UcSayininMinimumunuBul1(A, B, C)
enKucukSayi = min([A, B, C]);
참고 항목
카테고리
Help Center 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!