LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a custom array?

Solved!
Go to solution

I would like to built a custom array containing numbers from 0 to 128, I have already done that using a FOR loop and autoindexing. Now I'd like to append eight zero's after every 8 elements, so my new array would look like: 0,1,2,3,4,5,6,7,0,0,0,0,0,0,0,0,8,9,10,11,12,13,14,15,0,0,0,0,0,0,0,0,16,19, .... and so on. How can this be implemented? 

 

I tried using insert into array and build array functions, but I can't seem to figure it out. 

0 Kudos
Message 1 of 11
(784 Views)

Not sure how much smaller Altenbach can make it...

 

snip.png

Message 2 of 11
(777 Views)

Not smaller, but I don't use Build Array inside For loop.

PinguX_0-1721304828594.png

 

Message 3 of 11
(747 Views)

Thank you ! 

Additionally, could you recommend some resources (free) to learn logic building for LabVIEW specifically? I have a difficult time trying to make things on LabVIEW which I can easily code in text based languages such as C++/python.

0 Kudos
Message 4 of 11
(745 Views)

Hi Zain,

 


@ZainAli02 wrote:

could you recommend some resources (free) to learn logic building for LabVIEW specifically? I have a difficult time trying to make things on LabVIEW which I can easily code in text based languages such as C++/python.


The "logic" is always the same!

 

LabVIEW doesn't need "variables", you use wires instead… (THINK DATAFLOW!)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 11
(729 Views)

Does your initial array have 128 or 129(!) elements?  You said "from 0 to 128", which suggests you have a 128-element array [0, 1, ..., 126, 127] and add on a singleton 128.

 

I'm going to assume your original Array had 128 elements, so goes from 0 to 127.  I would handle this problem in a different way that uses no loops at all, but treats the Array as an "array" and does "array manipulation" to get your solution (that's the "mathematician" hat I'm currently wearing).  Here are the steps (verbally -- carrying them out will be a nice "teaching/learning" exercise).

  • Transform the 1D 128-element Array into a 2D 16x8 (16 rows of 8 elements) Array.  Row 0 should be 0..7.
  • Create (without using loops) a similar size Array of all 0's.
  • Concatenate the two Arrays to get a 16x16 Array (Row 0 now is 0..7, 0, 0, 0, 0, 0, 0, 0, 0).
  • Transform the 2D 256-element Array into a 1D 256-element Array.

So I wrote down these steps, but before pressing "Post", I decided to try it.  Oops, there's a "feature" that I forgot about, but there are work-arounds.  [It is simple enough to put some Array Indicators at output points to make sure you are doing what you think you are doing].

 

So my version of this "teaches" you some useful "Array-manipulation" functions that (if you use arrays much) will come in handy.  Enjoy the puzzle.

 

Bob Schor

 

Message 6 of 11
(711 Views)

@ZainAli02 wrote:

Additionally, could you recommend some resources (free) to learn logic building for LabVIEW specifically? I have a difficult time trying to make things on LabVIEW which I can easily code in text based languages such as C++/python.


Just wait until you get to (advanced) threading situations. You'll realize you don't have to worry at all about data integrity (and the related deadlocks\livelocks).

 

Or nD arrays (although n>2 is a code smell)...

Message 7 of 11
(677 Views)
Solution
Accepted by ZainAli02

Two flat loops tend to scale better than two stacked loops.

 

altenbach_0-1721313457512.png

 

(Not sure what to do with the "128" you seem to want, so adjust as needed)

 

 

 

Message 8 of 11
(664 Views)


The "logic" is always the same!

 

LabVIEW doesn't need "variables", you use wires instead… (THINK DATAFLOW!)


I am just a few months old into LabVIEW, could you point in any directions that could help me? 

0 Kudos
Message 9 of 11
(596 Views)

 


@Bob_Schor wrote:

 

So my version of this "teaches" you some useful "Array-manipulation" functions that (if you use arrays much) will come in handy.  Enjoy the puzzle.

 

 


Thank you Sir for this. It'll definitely help me in the longer run and I will surely give this some time to figure it out and implement it. The array is meant to be 128 elements, so from o to 127, that was a mistake on my end. 😅

0 Kudos
Message 10 of 11
(595 Views)