필터 지우기
필터 지우기

Choosing between to cases

조회 수: 2 (최근 30일)
tony karamp
tony karamp 2013년 1월 29일
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

채택된 답변

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

추가 답변 (2개)

Ilham Hardy
Ilham Hardy 2013년 1월 29일

tony karamp
tony karamp 2013년 1월 29일
Thank you everyone!!!

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by