how to combine switch statements for final message?

I was stuck on combining 2 switch statements for a final message of a program.
here is my code:
vec= input('enter provided code','s')-'0'
day=(vec(1)*vec(2)-vec(3))
switch day
case 1
disp ('Monday')
case 2
disp('Tuesday')
case 3
disp('Wednesday')
case 4
disp('Thursday')
....
if (mod(vec(4),3))
rvp= (vec(6)-vec(5))
switch rvp
case 1
disp('B')
case 2
disp('L')
case 3
disp('RC')
....
X= ['rescue at', str2num(day), 'at', str2num(rvp)]
disp(X)
here, i want it to display: rescue at Monday at L or something of that sort but when i try to enter something in i get:
enter provided code510129
Friday
rescue at5at1
can you please help how to put switch statements part of the final message using the display function?
thanks

Answers (1)

Do not disp() the values as soon as they are calculated. Assign them to a variable instead. And then at the end, put all the variables together.

2 Comments

how would i do that with multiple cases? can you please give me an example?
switch day
case 1
dayname = 'Monday';
case 2
dayname = 'Tuesday';
otherwise
dayname = '?Day?';
end
switch rvp
case 1
rvpcode = 'B';
case 2
rvpcode = 'L';
otherwise
rvpcode = '?RVP?';
end
result = [dayname, rvpcode];
Or....
daynames = {'Monday', 'Tuesday', 'Wednesday' ...};
rvpcodes = {'B', 'L', 'RC' ...};
dayname = daynames{day};
rvpcode = rvpcodes{rvp};
result = [dayname, rvpcode];
Notice the complete lack of switch/case

Sign in to comment.

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Asked:

on 19 Oct 2015

Edited:

on 20 Oct 2015

Community Treasure Hunt

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

Start Hunting!