Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Trouble with integrating functions with loop and switch

조회 수: 2 (최근 30일)
Dylan Flores
Dylan Flores 2014년 8월 1일
마감: MATLAB Answer Bot 2021년 8월 20일
*This is what I have so far below. I need to know how i can use functions to help calculate the area and circumference of the circle when the menu bar comes up. How do I add Function circleArea() and Function circleCircum() that will accept the radius and reveal the area and circumference respectively.*
flag =0;
%Calculation
while (1)
choice=menu('Circle and Cylinder', 'Enter the radius','Display the area', 'Display the circumference','Exit');
switch(choice)
case 1
r=circleInfo();
flag=1;
case 2
if (flag==0)
disp('you need to enter the radius first');
else
area=circleArea(r);
end
case 3
if (flag==0)
disp('You need to enter the radius first')
else
circumference = circleCircum(r)
end
end
end
  댓글 수: 1
Ashish Gudla
Ashish Gudla 2014년 8월 5일
By converting your script into a function (lets say "my_fun"), you can add the definitions for the other functions "circleArea" and "circleCircum" after the end of your "my_fun" function.
Also you might want to consider "inputdlg" (see doc) and "msgbox" (see doc) to accept the radius and display the calculated values.

답변 (0개)

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by