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 中查找有关 Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by