http://www.mathworks.com/matlabcentral/newsreader/view_thread/308118
MATLAB Central Newsreader  Logical Indexing
Feed for thread: Logical Indexing
enus
©19942014 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Sun, 22 May 2011 15:18:04 +0000
Logical Indexing
http://www.mathworks.com/matlabcentral/newsreader/view_thread/308118#837268
Alexander
I have two matrices. Nr.1 is a 469x7 and Nr.2 is a 469x20<br>
<br>
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. <br>
<br>
Each matrix represents signals which I now want to put "together" to form a combined signal matrix. <br>
<br>
Example:<br>
Nr.1: [1,0,0,0,0,0,1] > signal for the first and the seventh element <br>
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. <br>
<br>
As result I want to have: <br>
Nr.3:[1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0] <br>
<br>
Does anyone have an idea how to do that? <br>
<br>
Thanks.

Sun, 22 May 2011 15:27:06 +0000
Re: Logical Indexing
http://www.mathworks.com/matlabcentral/newsreader/view_thread/308118#837269
ImageAnalyst
Alexander<br>
I have no idea what you did. First of all, these are 1D matrices, not<br>
2D, and, inconveniently, aren't even MATLAB lines of code that we can<br>
run.<br>
<br>
Then, the "seventh" one is actually in a column, not a row since Nr2<br>
is a row vector.<br>
<br>
Finally, I have no idea how you "put together" your Nr1 and Nr2 to<br>
form your Nr3. I don't think you explained that. Could you explain<br>
that?

Sun, 22 May 2011 17:28:04 +0000
Re: Logical Indexing
http://www.mathworks.com/matlabcentral/newsreader/view_thread/308118#837282
Roger Stafford
"Alexander " <aimmler@gmail.com> wrote in message <irb9fc$lbr$1@newscl01ah.mathworks.com>...<br>
> I have two matrices. Nr.1 is a 469x7 and Nr.2 is a 469x20<br>
> <br>
> 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. <br>
> <br>
> Each matrix represents signals which I now want to put "together" to form a combined signal matrix. <br>
> <br>
> Example:<br>
> Nr.1: [1,0,0,0,0,0,1] > signal for the first and the seventh element <br>
> 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. <br>
> <br>
> As result I want to have: <br>
> Nr.3:[1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0] <br>
> <br>
> Does anyone have an idea how to do that? <br>
> <br>
> Thanks. <br>
         <br>
N3 = false(469,20);<br>
for k = 1:469<br>
f = find(N2(k,:));<br>
N3(k,f(find(N1(k,:)))) = true;<br>
end<br>
<br>
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.<br>
<br>
Roger Stafford