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:
Mod+loop

Subject: Mod+loop

From: Sylvie

Date: 25 Feb, 2009 13:11:01

Message: 1 of 4

Hello ,

I set-up the following loop to read images (thanks to R. Stafford) in order to read every 13th images.

for k=1:240
    if mod(k,3)==1

(...some formula)

    end
end

The problem is that I realized that I need to read the images every 3th than 4th images rather than just every 13th...
image1(read)
image2(no)
image3(no)
image 4(read) --3rd image--
image 4(no)
image 5 (no)
image 6(no)
image 7 (read) --4th image--
image8(no)
image9(no)
image 10(read) --3rd image--
image 11(no)
image 12(no)
image13(no)
image 14 (read) --4th image--
etc...

Any suggestions?

Sylvie

Subject: Mod+loop

From: Adam

Date: 25 Feb, 2009 17:35:03

Message: 2 of 4

"Sylvie " <sylpel@yorku.ca> wrote in message <go3g15$chq$1@fred.mathworks.com>...
> Hello ,
>
> I set-up the following loop to read images (thanks to R. Stafford) in order to read every 13th images.
>
> for k=1:240
> if mod(k,3)==1
>
> (...some formula)
>
> end
> end
>
> The problem is that I realized that I need to read the images every 3th than 4th images rather than just every 13th...

another approach to same problem

imgIdx = cumsum(repmat([3 4], [1, 34]));

for k = imgIdx

(...some formula)

end

~Adam

Subject: Mod+loop

From: Roger Stafford

Date: 25 Feb, 2009 20:20:19

Message: 3 of 4

"Sylvie " <sylpel@yorku.ca> wrote in message <go3g15$chq$1@fred.mathworks.com>...
> Hello ,
>
> I set-up the following loop to read images (thanks to R. Stafford) in order to read every 13th images.
>
> for k=1:240
> if mod(k,3)==1
>
> (...some formula)
>
> end
> end
>
> The problem is that I realized that I need to read the images every 3th than 4th images rather than just every 13th...
> image1(read)
> image2(no)
> image3(no)
> image 4(read) --3rd image--
> image 4(no)
> image 5 (no)
> image 6(no)
> image 7 (read) --4th image--
> image8(no)
> image9(no)
> image 10(read) --3rd image--
> image 11(no)
> image 12(no)
> image13(no)
> image 14 (read) --4th image--
> etc...
>
> Any suggestions?
>
> Sylvie

  If I understand you correctly, you want to read the images:1,4,7,10,14,17,20,23,27,30,33,36,40, etc., repeating the pattern every 13 images, as you have indicated with the term "(read)". Is that right? If so, you can use the 'floor' function with the following fractional expression. If that sequence isn't quite what you want, it would be necessary to adjust the expression's numbers appropriately.

for k=floor((8*(1:240)+25)/26)
  (...some formula using k-th image
end

Roger Stafford

Subject: Mod+loop

From: Roger Stafford

Date: 26 Feb, 2009 01:26:01

Message: 4 of 4

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <go4963$spg$1@fred.mathworks.com>...
> ......
> for k=floor((8*(1:240)+25)/26)
> (...some formula using k-th image
> end
> ......

  My thinking wasn't clear on that problem. What I gave you is just plain wrong, Sylvie. My apologies! The following should work, though.

for k = 1:240
 if mod(mod(k,13),3)==1
  % Do some process with k
 end
end

Roger Stafford

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