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:
Clearing blocks of an array efficiently

Subject: Clearing blocks of an array efficiently

From: James

Date: 22 Jul, 2009 11:13:06

Message: 1 of 7

Hi All

I have an array of values that I wish to alter using array operators. What I would like to do is remove blocks of information in the same way I can remove columns or rows, but keep the elements as 0 rather than reducing the size of the array.

example; for removal of rows and columns in an array I use the following
d =
     1 1 1 1 1
     1 1 1 1 1
     1 1 1 1 1
     1 1 1 1 1
     1 1 1 1 1
>> d(2:2:end,:)=0
d =
     1 1 1 1 1
     0 0 0 0 0
     1 1 1 1 1
     0 0 0 0 0
     1 1 1 1 1

What I would like to do instead of clear single rows, is clear multiple rows so I have something like:

     1 1 1 1 1
     1 1 1 1 1
     0 0 0 0 0
     0 0 0 0 0
     1 1 1 1 1

with a repetative nature. I've tried various things like d((2:2):2:end,:)=0 but to no avail.

hope you can help

Cheers

Jim

Subject: Clearing blocks of an array efficiently

From: Shanmugam Kannappan

Date: 22 Jul, 2009 11:24:05

Message: 2 of 7

"James " <james.downing@st.com> wrote in message <h46s82$j6u$1@fred.mathworks.com>...
> Hi All
>
> I have an array of values that I wish to alter using array operators. What I would like to do is remove blocks of information in the same way I can remove columns or rows, but keep the elements as 0 rather than reducing the size of the array.
>
> example; for removal of rows and columns in an array I use the following
> d =
> 1 1 1 1 1
> 1 1 1 1 1
> 1 1 1 1 1
> 1 1 1 1 1
> 1 1 1 1 1
> >> d(2:2:end,:)=0
> d =
> 1 1 1 1 1
> 0 0 0 0 0
> 1 1 1 1 1
> 0 0 0 0 0
> 1 1 1 1 1
>
> What I would like to do instead of clear single rows, is clear multiple rows so I have something like:
>
> 1 1 1 1 1
> 1 1 1 1 1
> 0 0 0 0 0
> 0 0 0 0 0
> 1 1 1 1 1
>
> with a repetative nature. I've tried various things like d((2:2):2:end,:)=0 but to no avail.
>
> hope you can help
>
> Cheers
>
> Jim
Hi,
for above operation do it like this...
d(3:4,:)=0
Shan........

Subject: Clearing blocks of an array efficiently

From: us

Date: 22 Jul, 2009 11:29:07

Message: 3 of 7

"James " <james.downing@st.com> wrote in message <h46s82$j6u$1@fred.mathworks.com>...
> Hi All
>
> I have an array of values that I wish to alter using array operators. What I would like to do is remove blocks of information in the same way I can remove columns or rows, but keep the elements as 0 rather than reducing the size of the array.
>
> example; for removal of rows and columns in an array I use the following
> d =
> 1 1 1 1 1
> 1 1 1 1 1
> 1 1 1 1 1
> 1 1 1 1 1
> 1 1 1 1 1
> >> d(2:2:end,:)=0
> d =
> 1 1 1 1 1
> 0 0 0 0 0
> 1 1 1 1 1
> 0 0 0 0 0
> 1 1 1 1 1
>
> What I would like to do instead of clear single rows, is clear multiple rows so I have something like:
>
> 1 1 1 1 1
> 1 1 1 1 1
> 0 0 0 0 0
> 0 0 0 0 0
> 1 1 1 1 1
>
> with a repetative nature. I've tried various things like d((2:2):2:end,:)=0 but to no avail.
>
> hope you can help
>
> Cheers
>
> Jim

one of the solutions

     bt=ones(3,4);
     ix1=[1,3];
     ix2=1;
     ix3=2:3;
     b1=bt; b1(ix1,:)=0;
     b2=bt; b2(ix2,:)=0;
     b3=bt; b3(ix3,:)=0;
     disp([b1;nan(1,4);b2;nan(1,4);b3]);
%{
     0 0 0 0 % <- b1
     1 1 1 1
     0 0 0 0
   NaN NaN NaN NaN
     0 0 0 0 % <- b2
     1 1 1 1
     1 1 1 1
   NaN NaN NaN NaN
     1 1 1 1 % <- b3
     0 0 0 0
     0 0 0 0
%}

us

Subject: Clearing blocks of an array efficiently

From: Caroline From France

Date: 22 Jul, 2009 11:32:03

Message: 4 of 7

"James " <james.downing@st.com> wrote in message <h46s82$j6u$1@fred.mathworks.com>...
> Hi All
>
> I have an array of values that I wish to alter using array operators. What I would like to do is remove blocks of information in the same way I can remove columns or rows, but keep the elements as 0 rather than reducing the size of the array.
>
> example; for removal of rows and columns in an array I use the following
> d =
> 1 1 1 1 1
> 1 1 1 1 1
> 1 1 1 1 1
> 1 1 1 1 1
> 1 1 1 1 1
> >> d(2:2:end,:)=0
> d =
> 1 1 1 1 1
> 0 0 0 0 0
> 1 1 1 1 1
> 0 0 0 0 0
> 1 1 1 1 1
>
> What I would like to do instead of clear single rows, is clear multiple rows so I have something like:
>
> 1 1 1 1 1
> 1 1 1 1 1
> 0 0 0 0 0
> 0 0 0 0 0
> 1 1 1 1 1
>
> with a repetative nature. I've tried various things like d((2:2):2:end,:)=0 but to no avail.
>
> hope you can help
>
> Cheers
>
> Jim

Hi

So you reel problem is to construct the row's index, no ?

In your first exemple it was :
idxR = 2:2:size(d,1)

In your second I'm not sure of what you want.
idxR = [2 3] does the job but I can't see how to generalize without a biggest example.

BTW, do you really want to replace by 0 ?
Because "clear" means for me :
d(idxR) = []
which will really delete the rows

Caroline

Subject: Clearing blocks of an array efficiently

From: James

Date: 22 Jul, 2009 12:02:04

Message: 5 of 7


> So you reel problem is to construct the row's index, no ?
>
> In your first exemple it was :
> idxR = 2:2:size(d,1)
>
> In your second I'm not sure of what you want.
> idxR = [2 3] does the job but I can't see how to generalize without a biggest example.
>
> BTW, do you really want to replace by 0 ?
> Because "clear" means for me :
> d(idxR) = []
> which will really delete the rows
>
> Caroline

Thanks for the inputu but I don't think I have explained the problem well enough.
I do want to replace the elements with a zero value, not NaN or delete.

The example I gave was a small arbitrary array, not really representative of the large array I wish to manipulate. The actual array is ~3200^2 square array with 3 colour channels.

I want to bayer sample the image in large blocks ~320x320 pixels so that the output image has the arrangement:

    R G R G R G R G .........
    
    G B G B G B G B..........

    R G R G R G R G .........
    
    G B G B G B G B..........
    : : : : : : : :
    : : : : : : : :

so for the red channel say, I need to set the values that occur over a green or blue channel to zero. This is easilty achieved for individual pixel bayer sampling as I mentioned in my first post R.E the rows and columns. As you can see, instead of single rows and columns, I wish to set 320 rows to zero, ignore the next 320 rows and then set the following 320 rows to zero again.
  Ii have code that will do it but it is iterative. I was wondering whether it was possible to write something like

               d([cellsize]:2*cellsize:end,:)=0

to block set rows to zero? If not, no worries

Subject: Clearing blocks of an array efficiently

From: us

Date: 22 Jul, 2009 12:16:03

Message: 6 of 7

"James " <james.downing@st.com> wrote in message <h46v3s$lui$1@fred.mathworks.com>...
>
> > So you reel problem is to construct the row's index, no ?
> >
> > In your first exemple it was :
> > idxR = 2:2:size(d,1)
> >
> > In your second I'm not sure of what you want.
> > idxR = [2 3] does the job but I can't see how to generalize without a biggest example.
> >
> > BTW, do you really want to replace by 0 ?
> > Because "clear" means for me :
> > d(idxR) = []
> > which will really delete the rows
> >
> > Caroline
>
> Thanks for the inputu but I don't think I have explained the problem well enough.
> I do want to replace the elements with a zero value, not NaN or delete.
>
> The example I gave was a small arbitrary array, not really representative of the large array I wish to manipulate. The actual array is ~3200^2 square array with 3 colour channels.
>
> I want to bayer sample the image in large blocks ~320x320 pixels so that the output image has the arrangement:
>
> R G R G R G R G .........
>
> G B G B G B G B..........
>
> R G R G R G R G .........
>
> G B G B G B G B..........
> : : : : : : : :
> : : : : : : : :
>
> so for the red channel say, I need to set the values that occur over a green or blue channel to zero. This is easilty achieved for individual pixel bayer sampling as I mentioned in my first post R.E the rows and columns. As you can see, instead of single rows and columns, I wish to set 320 rows to zero, ignore the next 320 rows and then set the following 320 rows to zero again.
> Ii have code that will do it but it is iterative. I was wondering whether it was possible to write something like
>
> d([cellsize]:2*cellsize:end,:)=0
>
> to block set rows to zero? If not, no worries

did you bother to look at the solution i showed you...

us

Subject: Clearing blocks of an array efficiently

From: James

Date: 23 Jul, 2009 11:30:21

Message: 7 of 7

Hi us

I did look at the solution but the solution needs to be dynamic. by applying this as I understand it, it will have to allocate small arrays that would each be different for various scenarios?

I have streamlined my iteration process and it works pretty quickly now but thanks for the suggestion.

Cheers

Jim

Tags for 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