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:
Select value from loop

Subject: Select value from loop

From: Sylvie

Date: 25 Feb, 2009 03:31:03

Message: 1 of 4

Hello there,

I set up a for loop to read 480 different image files. I would like to select every third images.

Image 1 (select)
Image2 (Dont select)
Image3(Dont select)
Image4(Select)
Image5 (Dont select)
Image6(Dont select)
Image7(select)
etc...

I am not sure which command I should use

Thanks

Sylvie

Subject: Select value from loop

From: Roger Stafford

Date: 25 Feb, 2009 03:44:04

Message: 2 of 4

"Sylvie " <sylpel@yorku.ca> wrote in message <go2e1n$6lq$1@fred.mathworks.com>...
> Hello there,
>
> I set up a for loop to read 480 different image files. I would like to select every third images.
>
> Image 1 (select)
> Image2 (Dont select)
> Image3(Dont select)
> Image4(Select)
> Image5 (Dont select)
> Image6(Dont select)
> Image7(select)
> etc...
>
> I am not sure which command I should use
>
> Thanks
>
> Sylvie

   If your for-loop has an index that goes from 1 to 480, you can write:

 for k = 1:480
  if mod(k,3)==1
   % then "select"
 end
end

Roger Stafford

Subject: Select value from loop

From: Godzilla

Date: 25 Feb, 2009 04:15:05

Message: 3 of 4

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <go2eq4$r8p$1@fred.mathworks.com>...
> "Sylvie " <sylpel@yorku.ca> wrote in message <go2e1n$6lq$1@fred.mathworks.com>...
> > Hello there,
> >
> > I set up a for loop to read 480 different image files. I would like to select every third images.
> >
> > Image 1 (select)
> > Image2 (Dont select)
> > Image3(Dont select)
> > Image4(Select)
> > Image5 (Dont select)
> > Image6(Dont select)
> > Image7(select)
> > etc...
> >
> > I am not sure which command I should use
> >
> > Thanks
> >
> > Sylvie
>
> If your for-loop has an index that goes from 1 to 480, you can write:
>
> for k = 1:480
> if mod(k,3)==1
> % then "select"
> end
> end
>
> Roger Stafford

if ~mod(k,3)
   % then "select"
 end

might be faster.

Subject: Select value from loop

From: Godzilla

Date: 25 Feb, 2009 04:26:03

Message: 4 of 4

"Godzilla " <godzilla@tokyo.edu> wrote in message <go2gk9$c0o$1@fred.mathworks.com>...
> "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <go2eq4$r8p$1@fred.mathworks.com>...
> > "Sylvie " <sylpel@yorku.ca> wrote in message <go2e1n$6lq$1@fred.mathworks.com>...
> > > Hello there,
> > >
> > > I set up a for loop to read 480 different image files. I would like to select every third images.
> > >
> > > Image 1 (select)
> > > Image2 (Dont select)
> > > Image3(Dont select)
> > > Image4(Select)
> > > Image5 (Dont select)
> > > Image6(Dont select)
> > > Image7(select)
> > > etc...
> > >
> > > I am not sure which command I should use
> > >
> > > Thanks
> > >
> > > Sylvie
> >
> > If your for-loop has an index that goes from 1 to 480, you can write:
> >
> > for k = 1:480
> > if mod(k,3)==1
> > % then "select"
> > end
> > end
> >
> > Roger Stafford
>
> if ~mod(k,3)
> % then "select"
> end
>
> might be faster.

My guess was wrong. The 'mod(k,3)==1' version seems a bit faster but hardly worth mentioning.

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