LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Three ways to generate X array

I have identified three ways I might want to generate a regularly spaced array, namely specifying:

 

1. Start Value, End Value, and Step Size

2. Start Value, Step Size, and Array Size

Or 3. Start Value, End Value, and Array Size

 

I have attached VIs to accomplish these three in case they are useful to anyone. They work for postive or negative step sizes and for start values greater or less than end values.

 

There are some subtleties associated with the first. Namely, if step size is such that the last value cannot be equal to the specified end value. I have elected to append the end value to the array by default, but leave this as an option.

_____________
Creator of the BundleMagic plugin for LabVIEW!
0 Kudos
Message 1 of 8
(2,855 Views)

Thanks for providing those, littlesphaeroid!

 

I recommend posting them as a Community Example - in my experience they're much easier to search for and find than a forum thread, and people can rate them and give feedback.

 

Regards,

Tom L.
0 Kudos
Message 2 of 8
(2,852 Views)
  • Make sure you don't duplicate the efforts we already have in "ramp pattern.vi".
  • Be careful with datatypes. A loop count of I16 is really not a good idea.
  • I would also avoid any use of OGTK tools, not everybody has those.
  • Avoid error popups. Just return an empty array (or error code) if a paramter is not valid.
  • ...
0 Kudos
Message 3 of 8
(2,834 Views)
  • Make sure you don't duplicate the efforts we already have in "ramp pattern.vi".

Are my examples entirely redundant? I like that they are named and easy to understand. But probably they are worthless.

 

  • Be careful with datatypes. A loop count of I16 is really not a good idea.

I don't really understand why this would be bad. Can you explain?

 

  • I would also avoid any use of OGTK tools, not everybody has those.

Would need to review my code, didn't realize I'd included this.

 

  • Avoid error popups. Just return an empty array (or error code) if a paramter is not valid.

I did this for my benefit. i assume it's a programmer error to specify a step size of zero and appreciate feedback. Seems to me an error output is impossible with no erro in/out (should such functions have errors clusters?). An empty array would be fine, though. I jsut elected to go a different route for my own purposes.

_____________
Creator of the BundleMagic plugin for LabVIEW!
0 Kudos
Message 4 of 8
(2,809 Views)

@littlesphaeroid wrote:
  • Be careful with datatypes. A loop count of I16 is really not a good idea.

I don't really understand why this would be bad. Can you explain?


If the count is I16, the maximum output array is 32k, which is very small for many modern problems. This means it is not possible to create a ramp larger than that. If the programmer wires e.g. a I32 with a larger value, expecting a larger output array, the output will be shorter than expected and there will be no obvious error generated (except for the red coercion dot). The native datatype for the N terminal of FOR loops is I32 and that's what you should be using.

 

 

 

0 Kudos
Message 5 of 8
(2,803 Views)

Oh, OK, that's good to know. I asked because I was thinking you might have meant the opposite. 

_____________
Creator of the BundleMagic plugin for LabVIEW!
0 Kudos
Message 6 of 8
(2,778 Views)

@littlesphaeroid wrote:

Oh, OK, that's good to know. I asked because I was thinking you might have meant the opposite. 


"The opposite" of what? Sorry I don't understand what you mean here..

0 Kudos
Message 7 of 8
(2,771 Views)

Oh, that I16 was an inappropriate choice because it allowed for an array that was too large. But my needs have not required generating an array that large. So I thought it was of sufficient size for my needs. Thanks for your help.

_____________
Creator of the BundleMagic plugin for LabVIEW!
0 Kudos
Message 8 of 8
(2,767 Views)