LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Snap to 1 • 2 • 5 Value

Solved!
Go to solution

Given any value, I want to snap it to a value such that the MSD is 1, 2, or 5, and the remaining digits are zeros.

Here's what I've come up with.

paul_a_cardinale_0-1766754205676.png

Can anyone come up with something better?

Message 1 of 12
(490 Views)

Plese check that

CLA
0 Kudos
Message 2 of 12
(460 Views)

Paul,

     Thanks for the brain-teaser.  I tried to figure out what you were doing from the image (didn't notice you'd actually attached code.  I recognized the "magic numbers" were log (2) and log (5), understood using log10 and exp10 to isolate "significant digits" and "location of decimal point", but the central function I didn't recognize, nor could I readily find it.

     Then I noticed you'd included the VI (thanks!!).  Turns out that's "Threshold 1D Array", which is part of a library (Scope?) that I don't have in my current installation of LabVIEW 2024.  I did read the description in the Help, and can see that it's something like "put this value in the correct bin of specified widths".  Probably if I installed the "Scope" library, I'd learn more about this function (which is possibly a malleable VI).

     My intuition is that this is probably as efficient as you are likely to get, as far as an algorithm is concerned.

     Where is the Library that contains this function?  What "loads" this Library?  Is it a Malleable VI, in fact?

 

Bob (always learning) Schor  

0 Kudos
Message 3 of 12
(450 Views)

Seems like a reasonable approach but I don't understand the need for EXT representation of the diagram constant.

 

0 Kudos
Message 4 of 12
(442 Views)
Solution
Accepted by topic author paul_a_cardinale

(cannot look at Ahmed's code)

 

Here's what I might do instead. Result differ somewhat because this operates on the linear range. Not sure what you prefer.

 

altenbach_0-1766774516182.png

 

Attached is a comparison. Note that in my case, the "bins" are filled more evenly.

 

altenbach_1-1766774582562.png

 

 

Message 5 of 12
(420 Views)

@paul_a_cardinale wrote:

Given any value, I want to snap it to a value such that the MSD is 1, 2, or 5, and the remaining digits are zeros.

Here's what I've come up with.

paul_a_cardinale_0-1766754205676.png

Can anyone come up with something better?


Are you looking for a Knob?  Like an O'Scope?  I think Dr. Darrin K had an algorithm a few years ago.   Even if he didn't,  a 1,2,5 progression is not as hard as you think it is 🤔 

 

3dB


"Should be" isn't "Is" -Jay
0 Kudos
Message 6 of 12
(403 Views)

@Bob_Schor wrote:

Paul,

     Thanks for the brain-teaser.  I tried to figure out what you were doing from the image (didn't notice you'd actually attached code.  I recognized the "magic numbers" were log (2) and log (5), understood using log10 and exp10 to isolate "significant digits" and "location of decimal point", but the central function I didn't recognize, nor could I readily find it.

     Then I noticed you'd included the VI (thanks!!).  Turns out that's "Threshold 1D Array", which is part of a library (Scope?) that I don't have in my current installation of LabVIEW 2024.  I did read the description in the Help, and can see that it's something like "put this value in the correct bin of specified widths".  Probably if I installed the "Scope" library, I'd learn more about this function (which is possibly a malleable VI).

     My intuition is that this is probably as efficient as you are likely to get, as far as an algorithm is concerned.

     Where is the Library that contains this function?  What "loads" this Library?  Is it a Malleable VI, in fact?

 

Bob (always learning) Schor  


"Threshold 1D Array" is a built-in function.  I thought it would be present in all versions of LV.

0 Kudos
Message 7 of 12
(394 Views)

@altenbach wrote:

Seems like a reasonable approach but I don't understand the need for EXT representation of the diagram constant.

 


Yields about 1 more digit of accuracy (but I don't really need it).

0 Kudos
Message 8 of 12
(390 Views)

@altenbach wrote:

(cannot look at Ahmed's code)

 

Here's what I might do instead. Result differ somewhat because this operates on the linear range. Not sure what you prefer.

 

altenbach_0-1766774516182.png

 

Attached is a comparison. Note that in my case, the "bins" are filled more evenly.

 

altenbach_1-1766774582562.png

 

 


I like it, but I'm more of a feedback-node kind of guy.

paul_a_cardinale_0-1766793889783.png

 

0 Kudos
Message 9 of 12
(384 Views)

@Bob_Schor wrote:

Paul,

     Thanks for the brain-teaser.  I tried to figure out what you were doing from the image (didn't notice you'd actually attached code.  I recognized the "magic numbers" were log (2) and log (5), understood using log10 and exp10 to isolate "significant digits" and "location of decimal point", but the central function I didn't recognize, nor could I readily find it.

     Then I noticed you'd included the VI (thanks!!).  Turns out that's "Threshold 1D Array", which is part of a library (Scope?) that I don't have in my current installation of LabVIEW 2024.  I did read the description in the Help, and can see that it's something like "put this value in the correct bin of specified widths".  Probably if I installed the "Scope" library, I'd learn more about this function (which is possibly a malleable VI).

     My intuition is that this is probably as efficient as you are likely to get, as far as an algorithm is concerned.

     Where is the Library that contains this function?  What "loads" this Library?  Is it a Malleable VI, in fact?

 

Bob (always learning) Schor  


I wasn't really trying to tease brains, just wondering if someone could come up with something better for me.

 

Ages ago I used to send brain teasers to my coworkers (usually VIs that didn't behave as expected).  Mostly they caught on fairly quickly; but eventually I stumped them with this one: Open the .vi file and both the FP & BD open, but they're both empty (really empty, not just stuff hidden from view).  Click the run button, and usually nothing would happen, but after a few to several times, the block diagram would fill in with some simple code.  Subsequent runs would just run that code.  The opposite of self-deleting code, this was self-writing code.  The trick stopped working sometime around '08.  If you remember some quirky old LV behaviors, you might be able to figure out what I did.

0 Kudos
Message 10 of 12
(379 Views)