Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8973687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:30:17+00:00 2026-06-15T18:30:17+00:00

I understand that the loops should not be nested but I have done the

  • 0

I understand that the loops should not be nested but I have done the same to further sub-divide the 5×5 window into four 3×3 sub-windows. Please help me with this, how to sub divide the 5×5 window into four 3×3 sub-windows without nested loop.

Code:

for i=1:m

for j=1:n

  if(i<=(m-4) && j<=(n-4))

      % Reading 5 x 5 window in an image

v=1; 
for p=i:i+4
    u=1;
    for q=j:j+4
        P(v,u)=L(p,q);
        u=u+1;
    end
    v=v+1;
end

    % Sub dividing the 5 x 5 window into four 3x3 sub windows 

k=1;
for r=1:3
    l=1;
    for s=1:3
        v2(k,l)=P(r,s);
        v1(k,l)=P(r,s+2);   
        v3(k,l)=P(r+2,s);
        v4(k,l)=P(r+2,s+2);
        l=l+1;    
    end
    k=k+1;
end

I need this four vector v1,v2,v3 and v4 for further processing. Link of my previous question about retaining the corner pixels:

https://stackoverflow.com/questions/13793103/retain-corner-pixels-in-an-image

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T18:30:19+00:00Added an answer on June 15, 2026 at 6:30 pm

    Let me tell a bit more than just answering your question on sub-dividing your window.

    1. You read in a 5×5 window from an image like this:

      P=L(i:(i+4),j:(j+4));

      so that (i,j) is the top-left corner of the window on the original image.

    2. This “sub-division” looks for me like taking a 3×3 starting from the TL, TR, BL and BR(*) corner of the 5×5 window. That can be done simply like this:

      tl = P(1:3, 1:3); % this is v2 in your question
      tr = P(1:3, 3:5); % this is v1 (didn't you mix up v2 and v1 by any chance?)
      bl = P(3:5, 1:3); % this is v3
      br = P(3:5, 3:5); % this is v4

      I suggest rather using this tl, tr, bl, br instead of v1, v2, v3, v4 because it is more expressive.

    (*)(T=top, B=bottom, L=left, R=right)


    UPDATE: (how to change the loops?)
    You want to cover all the windows on L, so the first window will be P=L(1:5, 1:5), the last will be P=L((m-4):m,(n-4):n). All the others will be in between. So the first value of i is i=1, the last is i=m-4 and the first j is j=1, the last is j=n-4.

    You can also verify this manually, typing a demo L into the command prompt of matlab, like this:

    L=reshape([1:42], 6, 7); % a 6x6 test array
    m=6; n=7;
    
    i=1; j=1;
    P_first=L(i:(i+4),j:(j+4)); % should contain 1
    
    i=m-4; j=n-4;
    P_last=L(i:(i+4),j:(j+4)); % should contain 42
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know from the codeing guidlines that I have read you should not do
I understand that I should not optimize every single point of my program, let's
I do understand that functions should not return references to automatic variables. However I
I have a blog that has a redirect loop, and I can't understand htaccess
I understand that applications under the same domain name can talk to each other
I understand that in CUDA's memory hierachy, we have things like shared memory, texture
Today I coded a function that uses two nested foreach loops. After seeing, that
I have a service that I am rewriting to use threading. I understand that
I have some Haskell code that does work correctly on an infinite list, but
Is it possible to write portable C code using nested functions/blocks? I understand that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.