LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to best initialize array to sequence of values

In MatLab (R2014a) you can do this:

 

a = linspace(1,100)

or

a = 1:100

and get an array of the numbers ranging from 1 to 100.

 

In "R" you can do this:

a <- seq(from=1,to=100,by=1)

and get the same. 

 

I could wrap something in a for loop to make my own array, but it seems inelegant.  I don't trust my own measures of elegance in LabVIEW/g yet. 

 

Is there a "recommended" way to intialize arrays to sequential, or skip-sequential values?

0 Kudos
Message 1 of 8
(6,366 Views)

Hi Student,

 

the FOR loop is quite nice: it's very effective in LabVIEW!

 

So just use a FOR loop, wire N to the N input and let i autoindex to get your array. When you want to have your array start with 1 (instead of 0) you add that 1 after the loop - or any other offset you need…

 

In the signal processing palette you find a Ramp function that mimics the functions of those other languages - you may find it "nicer" because it wraps your functionality in a subVI call…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 8
(6,362 Views)

Hi EngrStudent,

 

My name is Chris with National Instruments Applications Engineering. I watned to reiterate what GerdW mentioned about For Loops. I also wanted to recommend creating a SubVI to perform repeated functions. This definitely offers a more elegant solution and simplifies large chunks of LabVIEW code into a single icon with only the controls and indicators you need. The below article shows how to create SubVIs within your programs.

 

Using SubVIs

http://k12lab-support-pages.s3.amazonaws.com/lvadvancedhome3.html

 

I had some extra time and created the linspace function in LabVIEW. It is in the attached LabVIEW 2016 file. Let me know if you have any other questions!

Message 3 of 8
(6,267 Views)

@cdaug wrote:

 It is in the attached LabVIEW 2016 file.


a *.lvproj file does not contain any code. It is usless without the VIs in it.

0 Kudos
Message 4 of 8
(6,259 Views)

My apologies, forgot to zip it together. Here is the complete file!

0 Kudos
Message 5 of 8
(6,253 Views)

I think somewhere in the maths of signal generation palette there is a ramp function that allows you to set a start/end/delta and it generates an array with the required data.

 

I'll have a look tomorrow when I'm back at my desk 🙂


LabVIEW Champion, CLA, CLED, CTD
(blog)
Message 6 of 8
(6,252 Views)

Pretty sure this is the VI Sam was thinking of:

ramp by delta.png

 

It was indeed in the Signal Generation palette (which is in the Signal Processing palette...).

 

Alternately, if you actually have MatLab set up and installed on the same machine, you can just use that, since you're more familiar with it.MATLAB node.png

Message 7 of 8
(6,246 Views)

@Kyle97330 wrote:

Pretty sure this is the VI Sam was thinking of:

ramp by delta.png

 

It was indeed in the Signal Generation palette (which is in the Signal Processing palette...).


That's the one! I even had the inputs remembered as well. Go me. Thanks Kyle!


LabVIEW Champion, CLA, CLED, CTD
(blog)
Message 8 of 8
(6,217 Views)