01-18-2024 01:33 AM
I love how these simple questions often turn in a race to the bottom, who's gonna provide answer with the least functions/smallest size 😄
01-18-2024 03:26 AM - edited 01-18-2024 03:30 AM
@AeroSoul wrote:
I love how these simple questions often turn in a race to the bottom, who's gonna provide answer with the least functions/smallest size 😄
code golf 🙂 https://www.youtube.com/watch?v=MqZgoNRERY8
@rolfk wrote:
@crossrulz wrote:
@GerdW wrote:
What about this:
y := 1 - x
I was thinking to add 1 and then AND with 1. But yours is simpler still.
x = (x+1) && 1
a sparse occasion to use labviews expression node ...Gerd's approch is fairly easy to convert to primitives
the bitwise && gave me a little struggle to convert to primitives -
but wait, the 'formula node' and 'expression node' is based on C, and it turns out, && must be changed to &, as rolf predicted. nice!
01-18-2024 04:03 AM - edited 01-18-2024 04:16 AM
Because choice is so much fun, here my "limited" selection of options:
Caveat: they only work fine if the input is guaranteed to be in the range (0, 1). Other values will cause different results, some of them more intuitive than others. This is where Christian Altenbach's post comes in: we need to know the conditions and requirements for a proper selection of the various options.
And the -x + 1 only works for signed integers. The -x node refuses unsigned integers on its input, a sensible limitation. Interestingly the formula node version of this does not only not have this limitation but effectively still produces the right result. Apparently it promotes the value to a signed int internally and then converts it back to the input data type.
And I think I discovered a strange bug in the snippet generation. This is the actual VI block diagram from which the snippet was generated:
Anybody can notice the difference in two of the indicator labels?
01-18-2024 04:58 AM
@rolfk wrote:
Anybody can notice the difference in two of the indicator labels?
Isn't it just a simple LabVIEW rule: Don't have two indicators or controls with the same label?
By the way I see four differences.
01-18-2024 05:36 AM
@UliB wrote:
@rolfk wrote:
Anybody can notice the difference in two of the indicator labels?
Isn't it just a simple LabVIEW rule: Don't have two indicators or controls with the same label?
By the way I see four differences.
It's not something that is normally enforced. Yes, if you create new controls they will be made having unique labels but nothing prevents one from renaming them back. Seems the snippet tool is kind of recreating the diagram in the background through scripting to get the VI code. Possibly because I did not save the VI?
01-18-2024 10:41 AM
@rolfk wrote:
It's not something that is normally enforced.
<Offtopic> Similarly, I occasionally run into issues when just doing a copy/paste of graphs into e.g. MS paint. If a graph is set to autoscale, but the axes have been manually panned or zoomed, the pasted picture is autoscaled to the data again and thus looks different than on the front panel. Tedious! </oftopic>
01-19-2024 01:54 AM
Didn't even know you could do that, i normally just print screen stuff like this...
01-19-2024 02:50 AM - edited 01-19-2024 02:52 AM
Yes, LabVIEW is doing something with the code of the snippets. As you can see in my post here, at recipe 06 I overlooked the change of labels 😫, later I tried to give these labels unique names by a leading underscore, hidden (well, badly) by the terminal, as can be seen at 07 & 08.
A space will be trimmed and the label will then be renamed.