Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Quick case and switch question

Subject: Quick case and switch question

From: Diego Zegarra

Date: 26 Mar, 2009 04:09:02

Message: 1 of 6

I have a question on the following code. I want to go through all three cases first and then go down and update z, sol and cz. Right now the code goes to case 1 and then updates, then case 2 and updates, then case 3 and updates.

   for cycles=1:10
       switch parte
       case 1,
          [CmaxIns,InsSch,CTIns,parte]=insertion(z,sol,cz,m,n,M);
          Cmaxs(1)=CmaxIns; Progs{1,1}=InsSch; CTimes{1,1}=CTIns;
       case 2,
          [CmaxIE,IESch,CTIE,parte]=interexch(z,sol,cz,m,M);
          Cmaxs(2)=CmaxIE; Progs{2,1}=IESch; CTimes{2,1}=CTIE;
       case 3,
          [CmaxIAE,IAESch,CTIAE,parte]=intraexch(z,sol,cz,m,M);
          Cmaxs(3)=CmaxIAE; Progs{3,1}=IAESch; CTimes{3,1}=CTIAE;
       end
       [z pos]=min(Cmaxs);
       sol=Progs{pos,1};
       cz=CTimes{pos,1};
    end

Thanks for the help!

Subject: Quick case and switch question

From: Darren Rowland

Date: 26 Mar, 2009 04:19:01

Message: 2 of 6

If you want to 'go through all cases' why are you using a switch in the first place?

Subject: Quick case and switch question

From: Diego Zegarra

Date: 26 Mar, 2009 04:26:01

Message: 3 of 6

How would you go ahead and fix it?

Subject: Quick case and switch question

From: Darren Rowland

Date: 26 Mar, 2009 04:40:18

Message: 4 of 6

"Diego Zegarra" <diegozbb@gmail.com> wrote in message <gqf04p$6u2$1@fred.mathworks.com>...
> How would you go ahead and fix it?

I suppose I am struggling to understand what you want to achieve.
In the current code, at the first cycle, parte will have a single value from {1,2,3}.
The corresponding case is executed and parte gets a new value, then updates are made to z etc., and the next cycle commences.

From your description I am inclined to infer that you know, a priori, the value of parte at the first cycle, and you also know the sequence of values that parte will take when it is output from each function.
Is this true?
Darren

Subject: Quick case and switch question

From: Diego Zegarra

Date: 26 Mar, 2009 06:27:04

Message: 5 of 6

thats true

Subject: Quick case and switch question

From: Darren Rowland

Date: 26 Mar, 2009 07:39:02

Message: 6 of 6


Ok Diego,
My assumptions here are
- 'insertion' changes parte from 1 to 2
- 'interexch' changes parte from 2 to 3
- 'intraexch' changes parte from 3 back to 1
If this is true then parte is not needed. It has zero information content (in this piece of code). So the simple way to change your code is

> for cycles=1:10
> [Cmaxs(1),Progs{1,1},CTimes{1,1},dummy]=insertion(z,sol,cz,m,n,M);
> [Cmaxs(2),Progs{2,1},CTimes{2,1},dummy]=interexch(z,sol,cz,m,M);
> [Cmaxs(3),Progs{3,1},CTimes{3,1},dummy]=intraexch(z,sol,cz,m,M);

> [z pos]=min(Cmaxs);
> sol=Progs{pos,1};
> cz=CTimes{pos,1};
> end

If this is not what you want I'll have to get my crystal ball cleaned again.
Darren

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us