MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

### Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

# Switch case and a Menu Command

Asked by Taylor on 30 Nov 2012

I'm trying to create a code that calculates an output in one unit but displays the answer in six different unit (the answer is converted to different units). I have a menu command so that the user can choose from the six different units but I need a switch case as my logical structure. I'm completely lost on how to write the switch case (I'm very, very new to matlab, so forgive my ignorance).

```choice = menu('Choose a unit','in','ft','yd','m','cm','mm');
```
```R = input('Input a value for the radius:');
```
```result = (pi*R^2);
```
```switch choice
```
```      case 'in'
result = pi*R^2;```
```      case 'ft'
result = result/12;```
```      case 'yd'
result = result/36;```
```      case 'm'
result = result * .0254;```
```      case 'cm'
result = result * 2.54;```
```      case 'mm'
result = result * 25.4;```
```end
```

This was my first attempt that failed miserably, so any help would be appreciated.

## 1 Comment

Randy Souza on 3 Dec 2012

I have restored the original text of this question.

Taylor, this question has a clear subject and an answer, so it may be valuable to someone else in the future. If you have a good reason why it should be removed from MATLAB Answers, please flag the question, explain why it should be deleted, and an administrator or high-reputation contributor will consider deleting the question. Please do not simply edit your question away.

If you solved the problem on your own, please add your solution as an answer and accept it.

## Products

No products are associated with this question.