LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to limit size of an array?

Solved!
Go to solution

I'll figure something out eventually. 

0 Kudos
Message 21 of 36
(1,099 Views)

@User002 wrote:

Wouldn't that be using Boolan logic? 


What exactly do you consider Boolean Logic?

Are comparisons acceptable to use?

Frozen_0-1644595733606.png

 

---------------------------------------------
Certified LabVIEW Developer (CLD)
There are two ways to tell somebody thanks: Kudos and Marked Solutions
0 Kudos
Message 22 of 36
(1,092 Views)

You might want to re-think your general forum approach. Spending 50% of your answer dismissing posts by others is a sure way to prevent most people from answering. It really (really!) helps to be polite and thankful and I am sure you'll learn that eventually. Some of those are the best programmers anywhere and had valid concerns. Your own advice to them was not to answer, but you seem to answer every single one of them, violating your own rules!

 

Back to the original problem:

 

  • You are generating random integers from 0..100 and (0  and 100 only have half the probability as already mentioned).
  • You are excluding values 0, 71..89
  • You are keeping  1..70, 90..
  • Wouldn't it make more sense to generate random numbers 1..100 so the special case of 0 does not need to be handled?
  • Once you exclude your 0, a simple "in range and coerce" test could replace your entire case structure, making the code more readable (no code hidden in other cases).
  • If you want to implement special rules that complicate things (like writing your name, but by holding the pencil under water with your left toes while loud music is playing), you need to exactly define what these rules are. What do you consider "boolean logic" (anything from the boolean palette? green wires?). If you need to use a FOR loop, are you allowed to make it into a fake while loop (gigantic number wired to N, but showing the conditional terminal)? Are you still allowed to use other kinds of loops?

 

Now sit down and write five different programs that solve your problem. A few with your special rules and a few without any special rules. Show us your solutions and we will show what can be improved, putting you on the fast track to become a better programmer. Take the opportunity! 😄

0 Kudos
Message 23 of 36
(1,079 Views)

Here is a roundabout of limiting the array size:

Capture.PNG

Message 24 of 36
(1,072 Views)

@Gregory wrote:

Here is a roundabout of limiting the array size:


But you are not using a FOR loop and there is a green wire!

 

Here's a "solution" exclusively with FOR loops and nothing Boolean at all: 😄

 

altenbach_0-1644605032035.png

 

 

0 Kudos
Message 25 of 36
(1,066 Views)

@User002 wrote:

I want to build an array of a certain size by loops stopping when the array is full. I have to use a for loop and not use Boolean logic. I feel there's a connection to be made with the iteration count and count terminal but can't quite figure it out.


If you don't want to have a discussion then I suppose I'll just answer your question, though it seems contrived and nonsensical:

 

No. LabVIEW arrays do not have fixed sizes and cannot be "full". The size of the array is determined by how many elements are in it. If I have an array with 12 elements, it is of size 12, and I can always add more elements to make it size 13, or 14. In that sense an array is always "full" but can always be expanded.

 

Edit: Thought of an analogy. A LabVIEW array is not like a container that can be filled. An array is more like a stack of Legos. Your question is basically "Can I make a stack of Legos that is 12 bricks tall, then begin filling it and stop when it's full?" Your question implies a misunderstanding of how LabVIEW handles arrays. Other languages DO have fixed-size arrays, but LabVIEW does not.*

 

 

*To the pedants out there, yes LV FPGA has fixed size arrays and regular LV has fixed size queues, but I don't think that's what we're talking about here ;). The OP didn't say "how do I implement a fixed size array functionality", he/she said "can I fill up an array", and he/she doesn't seem to want to discuss the actual requirements.

0 Kudos
Message 26 of 36
(1,054 Views)

Sorry to revisit this ...

 

Lets say I only wanted to use the last 10 records (rows) of an array.  I know how to arrange the array from ascending / descending depending on the sorting a column (field).  

How would you only grab a set number of records?  Lets say the last/first 10 of an array.  

 

I was trying to build an array with a for loop with a initialize set at the first input.   My attempt to manipulate or limit the number of records has not been fruitful.  Has anyone tackled this?

0 Kudos
Message 27 of 36
(913 Views)

It would be very helpful to give a detailed example. You talk about sorting. Is that done once or can the sorting change later? How do you sort?

 

What's the datatype?

 

It is completely unclear how you manipulated unsuccessfully.

 

Once you explain in detail what "this" is, we can most likely offer a solution.

 

Please attach a small vi and some typical data.

0 Kudos
Message 28 of 36
(901 Views)

I was finally able to limit the number of desired records from an array using a for loop and an Insert into Array.vi

 

This was done on LV 2019.0.1f4 (64 bit)

Download All
0 Kudos
Message 29 of 36
(871 Views)

"excel sort data" is broken for me. Can you run your VI once until "all data descending" contains entries, then select that indicator and "edit...make selected values default. Now delete all excel code and turn the above indicator into a control ("right-click..change to control").

 

Save under a new name and attach it once more.

 

Now we have a runnable VI and can test the rest of your code. Seems extremely convoluted and I am sure there is a much better solution! trust me!

0 Kudos
Message 30 of 36
(859 Views)