COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

indexing question #6

• Email
• Follow

```Suppose I have an mx2 array of row,col values. What is a good way to
zero out elements at those locations in an array arr?
```
 0
Reply yaroslavvb (129) 9/29/2009 7:36:46 AM

See related articles to this posting

```"Yaroslav Bulatov" <yaroslavvb@gmail.com> wrote in message
> Suppose I have an mx2 array of row,col values. What is a good way to
> zero out elements at those locations in an array arr?
>

You mean 'arr' is a linear array of indices? as described in ind2sub? is so
try this:

EDU>> A=rand(3)
A =

0.6991    0.5472    0.2575
0.8909    0.1386    0.8407
0.9593    0.1493    0.2543

arr=[1,4,8];  %linear indices
A(arr)=0

A =

0         0    0.2575
0.8909    0.1386         0
0.9593    0.1493    0.2543

--Nasser

__________ Information from ESET NOD32 Antivirus, version of virus signature database 4465 (20090928) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

```
 0

```Yaroslav Bulatov <yaroslavvb@gmail.com> wrote in message <f0e49a6a-a509-4fe2-b12e-3a5e4f1ea634@a37g2000prf.googlegroups.com>...
> Suppose I have an mx2 array of row,col values. What is a good way to
> zero out elements at those locations in an array arr?

arr(  sub2ind(size(arr), mx2(:,1), mx2(:,2)    )   )=0
```
 0
Reply xys (1072) 9/29/2009 8:04:01 AM

```On Sep 29, 1:04=A0am, "Matt " <x...@whatever.com> wrote:
> Yaroslav Bulatov <yarosla...@gmail.com> wrote in message <f0e49a6a-a509-4=
> > Suppose I have an mx2 array of row,col values. What is a good way to
> > zero out elements at those locations in an array arr?
>
> arr( =A0sub2ind(size(arr), mx2(:,1), mx2(:,2) =A0 =A0) =A0 )=3D0

Thanks, that works. Interestingly, for a 480x480 arr and 100x2 mx2
this method is about 20 times slower (using single tic/toc
measurement) than looping over all rows of mx2, and setting
corresponding entries to 0 as below

for j=3D1:size(mx2,1)
arr(mx2(j,1),mx2(j,2))=3D0;
end
```
 0
Reply yaroslavvb (129) 10/1/2009 12:41:00 AM

```Yaroslav Bulatov <yaroslavvb@gmail.com> wrote in message <16920ae7-dfa4-44cc-af23-88d800f55041@f18g2000prf.googlegroups.com>...
> On Sep 29, 1:04?am, "Matt " <x...@whatever.com> wrote:
> > Yaroslav Bulatov <yarosla...@gmail.com> wrote in message <f0e49a6a-a509-4fe2-b12e-3a5e4f1ea...@a37g2000prf.googlegroups.com>...
> > > Suppose I have an mx2 array of row,col values. What is a good way to
> > > zero out elements at those locations in an array arr?
> >
> > arr( ?sub2ind(size(arr), mx2(:,1), mx2(:,2) ? ?) ? )=0
>
> Thanks, that works. Interestingly, for a 480x480 arr and 100x2 mx2
> this method is about 20 times slower (using single tic/toc
> measurement) than looping over all rows of mx2, and setting
> corresponding entries to 0 as below
>
>   for j=1:size(mx2,1)
>       arr(mx2(j,1),mx2(j,2))=0;
>   end

True, but there's a few things to keep in mind

(1) Did you generate mx2 using the find(LogicalMap) function? If you did, it was unnecessary, and is the only reason my proposed approach is required. You could have skipped creating mx2 at all and  just done arr(LogicalMap)=0, which has much less overhead.

(2) size(mx2,1)=100 is a very small number of coordinates. As it gets larger, the gap in speeds gets narrower.

(3) sub2ind.m is implemented in slow M-code, so it's not all that surprising that a for loop is better...
```
 0
Reply xys (1072) 10/1/2009 1:36:02 AM

4 Replies
98 Views

Similar Articles

12/14/2013 4:48:17 PM
page loaded in 488918 ms. (1)

Similar Artilces:

inv(rand(6,6,2)) question
The question is some what related to my earlier post about matix division: How come x=inv(rand(3,3,2)); gives this error: >> x=inv(rand(6,6,2)) ??? Error using ==> inv Input arguments must be 2-D. shouldn't each of the 2 matrcies in rand(6,6,2) give us a separate inverse? "Hydroman S" <amirgsalem@gmail.com> wrote in message <ggf2da\$898\$1@fred.mathworks.com>... > > shouldn't each of the 2 matrcies in rand(6,6,2) give us a separate inverse? > No. Bruno "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message &...

Re: If last question--data question #6 627360
The SQL solution is probably the most straightforward. You will have to place the GROUP BY clause before the HAVING clause. DATA step solutions also exist. The classic approach would be a two-stepper. First list the dates of interest: data lastdates; set herd; by herdcode ; keep herdcode testdate; if last.herdcode; run; Then merge with the original data and filter: data getlast2; merge herd lastdates(in=lastdate); by herdcode testdate; if lastdate; run; An alternative is to interleave the dataset with itself (two passes in one step). In this case ...

indexing question
Dear all, I am trying to create an index that gives the format page-number.paragraph-number for the index; where the paragraph numbers are generated but not for all paragraphs. The minimal example below gives the desired result for the main body of the document (in that the paragraphs are being correctly numbered) but when the index is generated it just gives the "final" paragraph number. Any ideas where to go from here? Many thanks in advance, Geoff. ------- minimal example---------- \documentclass{article} \usepackage{makeidx} \newcounter{margincounter}\setcounter{marginco...

Question #6
When I attempt a loft I get the "self intersecting geometry" error. What does it mean? What am I doing wrong? and how do I solve it? what it sounds like...the shape you have asked for folds or crosses over itself somewhere. check the order of your selections and the handle positions to make sure the loft flows correctly from one section to the other. also see that the direction of the start/end normals is correct and that the end conditions you have imposed are able to be to be achieved in the available space. if your preview disappears as you construct then you know you hav...

Indexing question
Hi. I'm just wondering if anyone knows a faster way to do THIS. I have a vector of 5 numbers, and a LARGE number of rows of information (say 1 million by 6). I want to return a 1/0 array, 1 million by FIVE, indicating whether or not each of the original 5 numbers is present in each row of information. For example, A = [2 6 10 17 23]; B = [1 10 23 48 100 6; 1 17 24 60 6 48]; needs to return C = [0 1 1 0 1; 0 1 0 1 0] because 6, 10, and 23 are in row 1, and 6 and 17 are in row 2. There are a LOT of rows of B. What I do currently is C = (B == A(1) + B == A(2) + ...) Any ot...

Question on index
When you have a large table (16000 rows, 56 columns in my case) ---------------------------------------------------------------- CREATE TABLE table ( table_id int, .... .... number_of_the_document int, name text, mothers_name text, ); ---------------------------------------------------------------- And you put an index on the atribute "number_of_the_document", for example. ---------------------------------------------------------------- CREATE INDEX idx_number_of_the_document ON table (numb...

Archive-Name: linux/faq/part6 URL: http://www.mainmatter.com/ Reply-to: rkiesling@mainmatter.com Posting-Frequency: weekly Last-modified: 12/04/2001 Expires: Mon, 12 Nov 2001 05:00:00 GMT /pub/linux/packages/GCC/ for binutils-2.6.0.2.bin.tar.gz. 9.5. GCC Says, "Internal compiler error." If the fault is repeatable (i.e., it always happens at the same place in the same file--even after rebooting and trying again, using a stable kernel) you have discovered a bug in GCC. See the GCC Info documentation (type F1-i in Emacs, and select GCC from the menu) for details on how to report the ...

Archive-Name: linux/faq/part6 URL: http://www.mainmatter.com/ Reply-to: rkiesling@mainmatter.com Posting-Frequency: weekly Last-modified: 12/04/2001 Expires: Mon, 12 Nov 2001 05:00:00 GMT /pub/linux/packages/GCC/ for binutils-2.6.0.2.bin.tar.gz. 9.5. GCC Says, "Internal compiler error." If the fault is repeatable (i.e., it always happens at the same place in the same file--even after rebooting and trying again, using a stable kernel) you have discovered a bug in GCC. See the GCC Info documentation (type F1-i in Emacs, and select GCC from the menu) for details on how to report the ...

Archive-Name: linux/faq/part6 URL: http://www.mainmatter.com/ Reply-to: rkiesling@mainmatter.com Posting-Frequency: weekly Last-modified: 12/04/2001 Expires: Mon, 12 Nov 2001 05:00:00 GMT /pub/linux/packages/GCC/ for binutils-2.6.0.2.bin.tar.gz. 9.5. GCC Says, "Internal compiler error." If the fault is repeatable (i.e., it always happens at the same place in the same file--even after rebooting and trying again, using a stable kernel) you have discovered a bug in GCC. See the GCC Info documentation (type F1-i in Emacs, and select GCC from the menu) for details on how to report the ...

Archive-Name: linux/faq/part6 URL: http://www.mainmatter.com/ Reply-to: rkiesling@mainmatter.com Posting-Frequency: weekly Last-modified: 12/04/2001 Expires: Mon, 12 Nov 2001 05:00:00 GMT /pub/linux/packages/GCC/ for binutils-2.6.0.2.bin.tar.gz. 9.5. GCC Says, "Internal compiler error." If the fault is repeatable (i.e., it always happens at the same place in the same file--even after rebooting and trying again, using a stable kernel) you have discovered a bug in GCC. See the GCC Info documentation (type F1-i in Emacs, and select GCC from the menu) for details on how to report the ...

Archive-Name: linux/faq/part6 URL: http://www.mainmatter.com/ Reply-to: rkiesling@mainmatter.com Posting-Frequency: weekly Last-modified: 12/04/2001 Expires: Mon, 12 Nov 2001 05:00:00 GMT /pub/linux/packages/GCC/ for binutils-2.6.0.2.bin.tar.gz. 9.5. GCC Says, "Internal compiler error." If the fault is repeatable (i.e., it always happens at the same place in the same file--even after rebooting and trying again, using a stable kernel) you have discovered a bug in GCC. See the GCC Info documentation (type F1-i in Emacs, and select GCC from the menu) for details on how to report the ...

Archive-Name: linux/faq/part6 URL: http://www.mainmatter.com/ Reply-to: rkiesling@mainmatter.com Posting-Frequency: weekly Last-modified: 12/04/2001 Expires: Mon, 12 Nov 2001 05:00:00 GMT /pub/linux/packages/GCC/ for binutils-2.6.0.2.bin.tar.gz. 9.5. GCC Says, "Internal compiler error." If the fault is repeatable (i.e., it always happens at the same place in the same file--even after rebooting and trying again, using a stable kernel) you have discovered a bug in GCC. See the GCC Info documentation (type F1-i in Emacs, and select GCC from the menu) for details on how to report the ...

Archive-Name: linux/faq/part6 URL: http://www.mainmatter.com/ Reply-to: rkiesling@mainmatter.com Posting-Frequency: weekly Last-modified: 12/04/2001 Expires: Mon, 12 Nov 2001 05:00:00 GMT /pub/linux/packages/GCC/ for binutils-2.6.0.2.bin.tar.gz. 9.5. GCC Says, "Internal compiler error." If the fault is repeatable (i.e., it always happens at the same place in the same file--even after rebooting and trying again, using a stable kernel) you have discovered a bug in GCC. See the GCC Info documentation (type F1-i in Emacs, and select GCC from the menu) for details on how to report the ...

Archive-Name: linux/faq/part6 URL: http://www.mainmatter.com/ Reply-to: rkiesling@mainmatter.com Posting-Frequency: weekly Last-modified: 12/04/2001 Expires: Mon, 12 Nov 2001 05:00:00 GMT /pub/linux/packages/GCC/ for binutils-2.6.0.2.bin.tar.gz. 9.5. GCC Says, "Internal compiler error." If the fault is repeatable (i.e., it always happens at the same place in the same file--even after rebooting and trying again, using a stable kernel) you have discovered a bug in GCC. See the GCC Info documentation (type F1-i in Emacs, and select GCC from the menu) for details on how to report the ...

Archive-Name: linux/faq/part6 URL: http://www.mainmatter.com/ Reply-to: rkiesling@mainmatter.com Posting-Frequency: weekly Last-modified: 12/04/2001 Expires: Mon, 12 Nov 2001 05:00:00 GMT /pub/linux/packages/GCC/ for binutils-2.6.0.2.bin.tar.gz. 9.5. GCC Says, "Internal compiler error." If the fault is repeatable (i.e., it always happens at the same place in the same file--even after rebooting and trying again, using a stable kernel) you have discovered a bug in GCC. See the GCC Info documentation (type F1-i in Emacs, and select GCC from the menu) for details on how to report the ...

Archive-Name: linux/faq/part6 URL: http://www.mainmatter.com/ Reply-to: rkiesling@mainmatter.com Posting-Frequency: weekly Last-modified: 12/04/2001 Expires: Mon, 12 Nov 2001 05:00:00 GMT /pub/linux/packages/GCC/ for binutils-2.6.0.2.bin.tar.gz. 9.5. GCC Says, "Internal compiler error." If the fault is repeatable (i.e., it always happens at the same place in the same file--even after rebooting and trying again, using a stable kernel) you have discovered a bug in GCC. See the GCC Info documentation (type F1-i in Emacs, and select GCC from the menu) for details on how to report the ...

Archive-Name: linux/faq/part6 URL: http://www.mainmatter.com/ Reply-to: rkiesling@mainmatter.com Posting-Frequency: weekly Last-modified: 12/04/2001 Expires: Mon, 12 Nov 2001 05:00:00 GMT /pub/linux/packages/GCC/ for binutils-2.6.0.2.bin.tar.gz. 9.5. GCC Says, "Internal compiler error." If the fault is repeatable (i.e., it always happens at the same place in the same file--even after rebooting and trying again, using a stable kernel) you have discovered a bug in GCC. See the GCC Info documentation (type F1-i in Emacs, and select GCC from the menu) for details on how to report the ...

Archive-Name: linux/faq/part6 URL: http://www.mainmatter.com/ Reply-to: rkiesling@mainmatter.com Posting-Frequency: weekly Last-modified: 12/04/2001 Expires: Mon, 12 Nov 2001 05:00:00 GMT /pub/linux/packages/GCC/ for binutils-2.6.0.2.bin.tar.gz. 9.5. GCC Says, "Internal compiler error." If the fault is repeatable (i.e., it always happens at the same place in the same file--even after rebooting and trying again, using a stable kernel) you have discovered a bug in GCC. See the GCC Info documentation (type F1-i in Emacs, and select GCC from the menu) for details on how to report the ...

Archive-Name: linux/faq/part6 URL: http://www.mainmatter.com/ Reply-to: rkiesling@mainmatter.com Posting-Frequency: weekly Last-modified: 12/04/2001 Expires: Mon, 12 Nov 2001 05:00:00 GMT /pub/linux/packages/GCC/ for binutils-2.6.0.2.bin.tar.gz. 9.5. GCC Says, "Internal compiler error." If the fault is repeatable (i.e., it always happens at the same place in the same file--even after rebooting and trying again, using a stable kernel) you have discovered a bug in GCC. See the GCC Info documentation (type F1-i in Emacs, and select GCC from the menu) for details on how to report the ...