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:
two matrix with some conditions..How?

Subject: two matrix with some conditions..How?

From: alfann

Date: 11 Jun, 2010 14:18:41

Message: 1 of 7

Hi there,
I have one question..could you please help me..?

I have this matrix:
ax=[1 0 0 0; 1 0 0 0; 1 1 0 2; 0 0 0 2]
Here is two chains:
1's chain
and
2's chain

If any chain start from the top of the matrix(ax), the value of the same positions for the whole chain in another matrix (U2) is equal to 100.
If any chain start from the bottom of the matrix(ax), the value of the same positions for the whole chain in another matrix (U2) is equal to 888.
so
U2 should be equal to:
U2=[100 0 0 0; 100 0 0 0; 100 100 0 888; 0 0 0 888]
how can I do that please?

Subject: two matrix with some conditions..How?

From: Walter Roberson

Date: 11 Jun, 2010 14:24:14

Message: 2 of 7

alfann wrote:

> I have one question..could you please help me..?
>
> I have this matrix:
> ax=[1 0 0 0; 1 0 0 0; 1 1 0 2; 0 0 0 2]
> Here is two chains:
> 1's chain
> and
> 2's chain
>
> If any chain start from the top of the matrix(ax), the value of the same positions for the whole chain in another matrix (U2) is equal to 100.
> If any chain start from the bottom of the matrix(ax), the value of the same positions for the whole chain in another matrix (U2) is equal to 888.
> so
> U2 should be equal to:
> U2=[100 0 0 0; 100 0 0 0; 100 100 0 888; 0 0 0 888]
> how can I do that please?

Earlier I asked you a bunch of specific questions about what a "chain"
meant to you. No-one can answer your queries until you have clarified that.

Subject: two matrix with some conditions..How?

From: alfann

Date: 11 Jun, 2010 15:11:12

Message: 3 of 7

Dear Walter Roberson,
I don't understand exactly what do you mean from your question.
If it is not clear, let me know to give you more explaining about it.
Thanks

Subject: two matrix with some conditions..How?

From: Matt Fig

Date: 11 Jun, 2010 15:50:05

Message: 4 of 7

I do not know what you mean by "chain" either. But for your example, this works:


U2 = ax;
U2(U2==1) = 100;
U2(U2==2) = 888

Subject: two matrix with some conditions..How?

From: alfann

Date: 11 Jun, 2010 15:57:46

Message: 5 of 7

I mean by "chain" as you see the matrix ax
there are two chains, each chain is connected to another position(may be right, down, right or left) except zeros.
Here, I have two chains:
1's chain
and
2's chain

Subject: two matrix with some conditions..How?

From: Matt Fig

Date: 11 Jun, 2010 16:14:04

Message: 6 of 7

Ah, if you have the image processing toolbox you can use bwlabel and cousins to find the connected regions. If not, perhaps this will help you:

http://www.mathworks.com/matlabcentral/fileexchange/21376-islands

Subject: two matrix with some conditions..How?

From: alfann

Date: 11 Jun, 2010 16:18:39

Message: 7 of 7

It is not corrected.

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