Got Questions? Get Answers.
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 a region of my matrix

Subject: select a region of my matrix

From: Patrick Diviacco

Date: 29 Oct, 2009 16:13:03

Message: 1 of 3

Hi,

how can I select all elements in



In other words, how can I write this code without the for loops ?
thanks


    for x = 1:size(image, 1)
        for y = 1:size(image, 2)
            

            if ( x > (targetX - xSize) && x < (targetX + xSize) ) && ( y > (targetY - ySize) && y < (targetY + ySize) )
               mask(x,y) = 1;
            end
            
        end
    end

Subject: select a region of my matrix

From: Peter Brooks

Date: 29 Oct, 2009 16:26:02

Message: 2 of 3

"Patrick Diviacco" <patrick.diviacco@gmail.com> wrote in message <hcceuf$o35$1@fred.mathworks.com>...
> Hi,
>
> how can I select all elements in
>
>
>
> In other words, how can I write this code without the for loops ?
> thanks
>
>
> for x = 1:size(image, 1)
> for y = 1:size(image, 2)
>
>
> if ( x > (targetX - xSize) && x < (targetX + xSize) ) && ( y > (targetY - ySize) && y < (targetY + ySize) )
> mask(x,y) = 1;
> end
>
> end
> end

Could you be a bit more specific ie. what's targetX and targetY, and what do you mean by selecting a region of your matrix? Do you want to output a smaller matrix from within your original one, or change the values in a section of it....?

Subject: select a region of my matrix

From: Patrick Diviacco

Date: 30 Oct, 2009 07:02:20

Message: 3 of 3

"Peter Brooks" <pbrooks@ermitagegroup.com> wrote in message <hccfmq$buo$1@fred.mathworks.com>...
> "Patrick Diviacco" <patrick.diviacco@gmail.com> wrote in message <hcceuf$o35$1@fred.mathworks.com>...
> > Hi,
> >
> > how can I select all elements in
> >
> >
> >
> > In other words, how can I write this code without the for loops ?
> > thanks
> >
> >
> > for x = 1:size(image, 1)
> > for y = 1:size(image, 2)
> >
> >
> > if ( x > (targetX - xSize) && x < (targetX + xSize) ) && ( y > (targetY - ySize) && y < (targetY + ySize) )
> > mask(x,y) = 1;
> > end
> >
> > end
> > end
>
> Could you be a bit more specific ie. what's targetX and targetY, and what do you mean by selecting a region of your matrix? Do you want to output a smaller matrix from within your original one, or change the values in a section of it....?

Sorry...
targetX, targetY and xSize and ySize, are just 4 different variables, not connected with the matrix...

Yes, I would like to select a smaller matrix.

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