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:
Logical Indexing

Subject: Logical Indexing

From: Alexander

Date: 22 May, 2011 15:18:04

Message: 1 of 3

I have two matrices. Nr.1 is a 469x7 and Nr.2 is a 469x20

Both are logicals containing ones and zeros. There are always less ones in Nr.1 than in Nr.2. Also, Nr.1 is a sub sample of Nr.2.

Each matrix represents signals which I now want to put "together" to form a combined signal matrix.

Example:
Nr.1: [1,0,0,0,0,0,1] --> signal for the first and the seventh element
Nr.2: [1,0,1,0,1,0,1,0,0,1,0,0,1, 1 ,1,0,0,0,0,1] --> signal wherever there is a one. The "seventh" one in the row is seperated by spaces.

As result I want to have:
Nr.3:[1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0]

Does anyone have an idea how to do that?

Thanks.

Subject: Logical Indexing

From: ImageAnalyst

Date: 22 May, 2011 15:27:06

Message: 2 of 3

Alexander
I have no idea what you did. First of all, these are 1D matrices, not
2D, and, inconveniently, aren't even MATLAB lines of code that we can
run.

Then, the "seventh" one is actually in a column, not a row since Nr2
is a row vector.

Finally, I have no idea how you "put together" your Nr1 and Nr2 to
form your Nr3. I don't think you explained that. Could you explain
that?

Subject: Logical Indexing

From: Roger Stafford

Date: 22 May, 2011 17:28:04

Message: 3 of 3

"Alexander " <aimmler@gmail.com> wrote in message <irb9fc$lbr$1@newscl01ah.mathworks.com>...
> I have two matrices. Nr.1 is a 469x7 and Nr.2 is a 469x20
>
> Both are logicals containing ones and zeros. There are always less ones in Nr.1 than in Nr.2. Also, Nr.1 is a sub sample of Nr.2.
>
> Each matrix represents signals which I now want to put "together" to form a combined signal matrix.
>
> Example:
> Nr.1: [1,0,0,0,0,0,1] --> signal for the first and the seventh element
> Nr.2: [1,0,1,0,1,0,1,0,0,1,0,0,1, 1 ,1,0,0,0,0,1] --> signal wherever there is a one. The "seventh" one in the row is seperated by spaces.
>
> As result I want to have:
> Nr.3:[1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0]
>
> Does anyone have an idea how to do that?
>
> Thanks.
- - - - - - - - - -
N3 = false(469,20);
for k = 1:469
 f = find(N2(k,:));
 N3(k,f(find(N1(k,:)))) = true;
end

This assumes that "There are always less ones in Nr.1 than in Nr.2" really means that the number of true's in each row of N2 is always as great as the column number of the last 'true' in that row of N1.

Roger Stafford

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