how to combine switch statements for final message?
Afficher commentaires plus anciens
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
Réponses (1)
Walter Roberson
le 19 Oct 2015
0 votes
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 commentaires
Astha Sharma
le 19 Oct 2015
Walter Roberson
le 20 Oct 2015
Modifié(e) : Walter Roberson
le 20 Oct 2015
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
Catégories
En savoir plus sur Interactive Control and Callbacks dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!