| MATLAB Central > MATLAB Newsreader > Picking Ones among Zeros |
|
|
|
Subject: Picking Ones among Zeros From: Frederic Sigoillot Date: 4 Jul, 2009 21:44:02 Message: 1 of 28 |
|
Hello, |
|
On Jul 4, 5:44 pm, "Frederic Sigoillot" <sigoil...@yahoo.fr> wrote: |
|
ImageAnalyst <imageanalyst@mailinator.com> wrote in message <9032f492-3164-4f68-bb9a-7af6be64fb2f@o6g2000yqj.googlegroups.com>... |
|
If you don't have bwlabel, this should work: |
|
"Matt Fig" <spamanon@yahoo.com> wrote in message <h2okru$frv$1@fred.mathworks.com>... |
|
"Steve Amphlett" <Firstname.Lastname@Where-I-Work.com> wrote in message |
|
Since I wrote the SplitVec on FEX, I'm kind of lazy to think about using stock functions: |
|
"Matt Fig" <spamanon@yahoo.com> wrote in message <h2okru$frv$1@fred.mathworks.com>... |
|
"Frederic Sigoillot" <sigoillot@yahoo.fr> wrote in message <h2oif2$g5h$1@fred.mathworks.com>... |
|
On Jul 4, 2:44 pm, "Frederic Sigoillot" <sigoil...@yahoo.fr> wrote: |
|
"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message |
|
> |
|
Siyi Deng <mr.siyi.deng@gmail.com> wrote in message <987ab093-7a3a-4f31-a470-832243bcbce9@q40g2000prh.googlegroups.com>... |
|
On Jul 6, 1:30 pm, "Bruno Luong" <b.lu...@fogale.findmycountry> wrote: |
|
Another (one-liner) solution: |
|
And another one |
|
For long vectors it may be worthwhile to avoid the one liners. Calling find twice on the whole array seems to be the culprit. It is interesting to see so many solutions to a problem which is so simple to state. |
|
How (fast) they perform on my hardware: |
|
The same order, and on my machine (sorry I forgot to post this the first time): |
|
Result change a little bit if input is LOGICAL. I also add clean up CLEAR on the garbage of various codes to make sure there is little interference by memory allocation. |
|
"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message |
|
Siyi Deng <mr.siyi.deng@gmail.com> wrote in message <dd44bfac-dbcb-4a24-aff0-e8d97d454878@m7g2000prd.googlegroups.com>... |
|
"Matt " <xys@whatever.com> wrote in message <h3000a$c3n$1@fred.mathworks.com>... |
|
"Matt Fig" <spamanon@yahoo.com> wrote in message <h2u429$f57$1@fred.mathworks.com>... |
|
Just for fun I wanted to see what a good For loop solution could do. I was totally surprised by how well it places in the pack. For the 'double' case, it is first on both my machines (32bit, winvista, 4GB,2007a .... 64bit,winxp,16GB,2007b), and for the 'logical' case, it is second. This using the same bench function we have been passing around. |
|
On a similar note, what would be the simplest way to find location of ones in a binary string? |
|
"Hira Manzoor" <09020087@lums.edu.pk> wrote in message <h9ut4s$nku$1@fred.mathworks.com>... |
|
Hmmm.. that was pretty simple. I'm new to MATLAB and coding. My actual problem is that I want to create a strip with 8 bars at fixed locations. My ultimate purpose is to write a program that generates all possible 256 strips based on whether specific bars were present absent. One way could be use all binary numbers from 0 to 255 and bars should appear at locations where the binary number has ones. So my binary number is stored as a number not a matrix and find(x) doesn't help. Is there a way out for this or an easier way to do the above? |
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.
| Tag Activity for This Thread | ||
|---|---|---|
| Tag | Applied By | Date/Time |
| golf | Ned Gulley | 4 Aug, 2009 14:11:43 |
| bwlabel | Matt Fig | 4 Jul, 2009 18:41:43 |
| getchunks | Oleg Komarov | 4 Jul, 2009 18:19:04 |
| binary | Oleg Komarov | 4 Jul, 2009 18:19:04 |
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.
Contact us at files@mathworks.com