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:
I want this loop to repeat

Subject: I want this loop to repeat

From: Victoria Emberle

Date: 17 Dec, 2010 20:25:32

Message: 1 of 4

Hello,

I want my code to repeat through all of the i=1,2,3,4,.....,NumbCTImgs. Right now the code does not loop through them all it breaks and this is not what I want.


for i=1:NumbCTImgs
    CTset1SeriesUID=CT_SeriesUID(1);
 if CT_SeriesUID(i)~=CTset1SeriesUID;
     numB=numB+1;
    CTset2SeriesUID=CT_SeriesUID(i);
 
    break;
 end
end

Subject: I want this loop to repeat

From: Sean de

Date: 17 Dec, 2010 20:37:04

Message: 2 of 4

"Victoria Emberle" <emberley@uvic.ca> wrote in message <ieggvs$sgi$1@fred.mathworks.com>...
> Hello,
>
> I want my code to repeat through all of the i=1,2,3,4,.....,NumbCTImgs. Right now the code does not loop through them all it breaks and this is not what I want.
>
>
> for i=1:NumbCTImgs
> CTset1SeriesUID=CT_SeriesUID(1);
> if CT_SeriesUID(i)~=CTset1SeriesUID;
> numB=numB+1;
> CTset2SeriesUID=CT_SeriesUID(i);
>
> break;
> end
> end

Well then get rid of the
break;
command. What would you expect to happen? The first time your if statement is true the loop dumps.

Subject: I want this loop to repeat

From: Walter Roberson

Date: 17 Dec, 2010 20:37:58

Message: 3 of 4

On 10-12-17 02:25 PM, Victoria Emberle wrote:

> I want my code to repeat through all of the i=1,2,3,4,.....,NumbCTImgs. Right
> now the code does not loop through them all it breaks and this is not what I
> want.
>
>
> for i=1:NumbCTImgs
> CTset1SeriesUID=CT_SeriesUID(1);
> if CT_SeriesUID(i)~=CTset1SeriesUID;
> numB=numB+1;
> CTset2SeriesUID=CT_SeriesUID(i);
>
> break; end
> end


Are you looking for the number of unique CT_SeriesUID,

length(unique(CT_SeriesUID))

or are you looking for the number of times the CT_SeriesUID vector changes,

sum(logical(diff(CT_SeriesUID)))

or something else?


If you want to loop through everything, why do you have the 'break' statement?
break breaks out of the enclosing loop, and the enclosing loop is the 'for i'
loop.

Subject: I want this loop to repeat

From: Victoria Emberle

Date: 17 Dec, 2010 20:52:05

Message: 4 of 4

Nevermind I figured it out sorry. I shouldn't give up right away !! If I removed the break the code wouldn't loop but I found a mistake somewhere else.

Tags for this Thread

No tags are associated with 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