Help using switch statement

조회 수: 3 (최근 30일)
Steven
Steven 2012년 3월 17일
I have a problem dealing with a switch statement but I am having problems with it.
Here is the problem:
The following table gives the approximate values of the static coefficient of friction "u" for vaious materials.
  • Metal on metal, u=0.20
  • wood on wood, u=0.35
  • Metal on wood, u=0.40
  • Rubber on concrete, u=0.70
To start a weight 'W' moving on a horizontal surface, you must push with a force 'F', where F= u*W. Write a MATLAB program that uses the switch structure to compute the force 'F'. The program should accept as the input the value of W and the type of materials.
PLEASE HELP! Thank You.
  댓글 수: 1
Oleg Komarov
Oleg Komarov 2012년 3월 17일
http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer

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

답변 (1개)

Image Analyst
Image Analyst 2012년 3월 17일
This doesn't make sense. You can't switch on the input W because switch normally takes fixed, discrete values (though you can put in an expression). Plus it just doesn't make any sense to switch on W since your formula doesn't have any multiple cases that are different depending on the value of W in any way, shape, or form - it's the same formula no matter what W is - it only depends on u, not W. You could switch on u, but your instructions didn't say how u was to be decided on. Are you going to ask the user for u (or the material type) also? If so, you could switch on u (or the material name) and inside the switch perform the F=u*W formula.
  댓글 수: 2
Steven
Steven 2012년 3월 17일
Yes, I think it says that the program should accept The input the value of W and u so that is user input. Can you help me now?
Walter Roberson
Walter Roberson 2012년 3월 17일
m = input('Whatcha gonna do?',s);
switch m
case 'petal to the metal': u = 2/9;
case 'rubber hits the road': u = 3/4;
end

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

카테고리

Help CenterFile Exchange에서 Condensed Matter & Materials Physics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by