MATLAB Answers

Choosing between to cases

6 views (last 30 days)
tony karamp
tony karamp on 29 Jan 2013
hello all,
so I found myself in a situation where I have a switch case with two inputs
"switch blah blah
case ['car','pizza']
blah blah blah
plot (x,z)
xlabel 'fixed'
%for the case of 'car' I need to have a different ylabel
than the 'pizza' case
%for 'car'
ylabel 'gas'
%for 'pizza'
ylabel 'cheese'
end"
the thing is that every time I have 'car' or 'pizza' the same thing has to happen. the only difference between those two is that I need to name the ylabel of my plot repenting on the case. I could copy paste the whole thing but with a different name, but there are too many lines and it will slow down the process.
Any suggestions? Thank you in advance

  0 Comments

Sign in to comment.

Accepted Answer

Jan
Jan on 29 Jan 2013
switch string
case {'car','pizza'} % Curly braces
plot (x,z)
xlabel 'fixed'
if strcmp(string, 'car')
ylabel 'gas'
else
ylabel 'cheese'
end
end

  0 Comments

Sign in to comment.

More Answers (2)

Ilham Hardy
Ilham Hardy on 29 Jan 2013

  0 Comments

Sign in to comment.


tony karamp
tony karamp on 29 Jan 2013
Thank you everyone!!!

  0 Comments

Sign in to comment.