10-17-2016 09:42 AM - edited 10-17-2016 09:43 AM
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?
10-17-2016 09:47 AM - edited 10-17-2016 09:49 AM
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…
10-19-2016 05:00 PM
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!
10-19-2016 05:11 PM
@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.
10-19-2016 05:17 PM
My apologies, forgot to zip it together. Here is the complete file!
10-19-2016 05:18 PM
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 🙂
10-19-2016 05:35 PM - edited 10-19-2016 05:35 PM
Pretty sure this is the VI Sam was thinking of:
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.
10-20-2016 03:12 AM
@Kyle97330 wrote:Pretty sure this is the VI Sam was thinking of:
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!