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:
calculate centres and areas in 2 dim 0-1 array

Subject: calculate centres and areas in 2 dim 0-1 array

From: Christian Eschermann

Date: 11 May, 2010 11:27:04

Message: 1 of 2

Hello,

I need the centres of the „0-areas“ in a 2-dim 0-1-array . Moreover I need the size of each area.

Example:

z = [
1 1 0 1 1;
1 0 0 0 1;
1 1 0 1 1;
1 1 1 1 1;
1 0 0 0 1]

Result:

Centre, Area:
C1 = 12, A1 = 5
C2 = 15, A2 = 3

It’s easy to find centres by using „mean“. But I need a hint how to differentiate between different 0-areas.

For the area-sizes I found this:

>> z = [1 1 1 0 1 1 0 0 1 0 1 1 0 1 1 1];
>> l = findstr([0 z 0],[1 0])-findstr([0 z 0],[0 1])

l =

     3 2 1 2 3

Problem: „findstr“ doesn’t work in a 2-dim array. Is there any alternative?


Thank you.
Christian

Subject: calculate centres and areas in 2 dim 0-1 array

From: Sean

Date: 11 May, 2010 11:36:03

Message: 2 of 2

"Christian Eschermann" <christian.eschermann@still.de> wrote in message <hsbeu8$f82$1@fred.mathworks.com>...
> Hello,
>
> I need the centres of the „0-areas“ in a 2-dim 0-1-array . Moreover I need the size of each area.
>
> Example:
>
> z = [
> 1 1 0 1 1;
> 1 0 0 0 1;
> 1 1 0 1 1;
> 1 1 1 1 1;
> 1 0 0 0 1]
>
> Result:
>
> Centre, Area:
> C1 = 12, A1 = 5
> C2 = 15, A2 = 3
>
> It’s easy to find centres by using „mean“. But I need a hint how to differentiate between different 0-areas.
>
> For the area-sizes I found this:
>
> >> z = [1 1 1 0 1 1 0 0 1 0 1 1 0 1 1 1];
> >> l = findstr([0 z 0],[1 0])-findstr([0 z 0],[0 1])
>
> l =
>
> 3 2 1 2 3
>
> Problem: „findstr“ doesn’t work in a 2-dim array. Is there any alternative?
>
>
> Thank you.
> Christian

Do you have the image processing toolbox? If so:
>>help bwconncomp
>>help regionprops
Those two will do exactly what you want.

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