using different cases of switch command with if else

I am new to matlab. I have a question that, is it possible that different cases used in switch command can be used out side switch with if-else command.
I have a code which is given as follow
what I want to know is whether "p(1)" is calling "case 1" or it is different.

4 件のコメント

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 8 月 25 日
Why did you post a code as an image?
ritzm
ritzm 2013 年 8 月 25 日
because they are not shown properly in preview.
Laurent
Laurent 2013 年 8 月 25 日
If you use the 'Code' button on your code it will show up as proper code. Alternatively you can put two spaces in front of each line of your code. This gives the same result.
ritzm
ritzm 2013 年 8 月 25 日
thanks

サインインしてコメントする。

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 8 月 25 日
編集済み: Azzi Abdelmalek 2013 年 8 月 25 日

0 投票

loc=2
switch loc
case 1
P=[170 255 280]
case 2
p=[120 155 190]
end
This code means:
if loc==1
P=[170 255 280]
elseif loc==2
P=[120 155 190]
end

2 件のコメント

ritzm
ritzm 2013 年 8 月 25 日
編集済み: ritzm 2013 年 8 月 25 日
Thank you Sir for your reply. So according to you in my given code p(1) is different and is not calling case 1 from switch loc.
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 8 月 25 日
In your code you've used switch loc. That means: if loc==number then case number will be executed. Your switch case does not depend on P, It depends on loc

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeSearch Path についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by