Info

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

How do I use input function when trying to create this script?

조회 수: 2 (최근 30일)
T.Y. Hilton
T.Y. Hilton 2018년 2월 28일
댓글: Stephen23 2018년 2월 28일
Here is my assignment: Repeat the Fence problem from three assignments ago, this time saving it as a script and using the input() function rather than having constants for area, straight cost, and curved cost values. The upper limit for the radius independent variable should be computed (assume length of zero). Use disp() and [ ] to construct sentences to deliver the answers. The format string within num2str should be used to limit the numbers to two decimal places.
Here is my code from my last assignment:
>> Area = 1600;
>> StrCo = 30;
>> CurCo = 40;
>> R = [.01:.01:sqrt(2*Area/pi)];
>> L = (Area-.5*pi*R.^2)./(2*R);
>> Cost = (2*L+ 2*R)*StrCo +pi*R*CurCo;
>> [BestCost, Index] = min(Cost)
BestCost =
5.1575e+03
Index =
1861
>> BestR = R(Index)
BestR =
18.6100
>> BestL = L(Index)
BestL =
28.3714
I'm just having a lot of trouble saving this as a script and I have no clue how to use the input() function in this case! Just to clarify, R=Radius, StrCo = Straight Cost, CurCo = Curved Cost, and L=Length
  댓글 수: 1
Stephen23
Stephen23 2018년 2월 28일
duplicate:
https://www.mathworks.com/matlabcentral/answers/385357-i-need-help-with-using-the-input-function

답변 (1개)

KSSV
KSSV 2018년 2월 28일
prompt = 'Enter the value of Radius: ';
R = input(prompt,'s')
R = num2str(R) ;
  댓글 수: 2
T.Y. Hilton
T.Y. Hilton 2018년 2월 28일
Oh gotcha! Now do I do that for the Area, Straight, and Curved Costs as well?
Stephen23
Stephen23 2018년 2월 28일
num2str makes no sense, you actually need str2double.

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

Community Treasure Hunt

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

Start Hunting!

Translated by