LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

save array of numbers in different arrays

Solved!
Go to solution

hi

in my code bellow i have three adjustable numbers and three array indicators.in the case structure user can choose number between 0 to 2 and depends on the number the 3 adjustable numbers going in array 1 or 2 or 3.

for example user chooses adjustable numbers 3 4 5 and also chooses case structure 0 by pressing add button these numbers go consecutive in the index 0 1 2 on array 1 and if the user push it again new number go to next indexes on array 1 and the previous data won't be lost.

now if the user chooses case 2 this process is done for array 2  without losing data on array 1.

my problem is here when i choose new case structure and press add button for the first time after choosing case my adjustable numbers go to my previous array  ، my second press send it to array2.

can anyone help me?

Thankyou.

0 Kudos
Message 1 of 11
(2,243 Views)

You have a race condition because the numeric gets read before the event structure fires, so if you change it, the new value gets only applied at the next iteration. You also don't have an event for the stop button.

0 Kudos
Message 2 of 11
(2,220 Views)

DataFlow!

 

Your Numeric indicator is read pretty much immediately when your loop iteration starts.  Then it waits around at the event structure until the event happens.  Even if you change the numeric value, it won't get read again until the next iteration.

 

The numeric terminal belongs in the even case so it isn't read until you press the Add button.  You may have to rearrange other code like bringing the first case structure into the event case as well.

 

Run your code with highlight execution turned on so you can understand what is happening.

0 Kudos
Message 3 of 11
(2,216 Views)
Solution
Accepted by topic author ehsan75

Here's one possible solution.

 

 

0 Kudos
Message 4 of 11
(2,211 Views)

Thank you very very much

0 Kudos
Message 5 of 11
(2,147 Views)
Solution
Accepted by topic author ehsan75

Of course my solution is not really scalable and would become quite complicated if the number of arrays would need to be increased. Here is the same using arrays of controls and indicators.

(Since ragged 2D arrays are not possible, we need to do a 1D cluster array for the output.)

 

Here's how that could look like.

 

altenbach_0-1587826214861.png

 

Now only very minor changes are needed to e.g. change the number of "hour" controls or the number of ragged columns.

 

0 Kudos
Message 6 of 11
(2,144 Views)

this code is very good but what should i do if i want to access to each column data separated from each other.

how can i separate columns and access them in my block diagram?

0 Kudos
Message 7 of 11
(2,134 Views)

@ehsan75 wrote:

this code is very good but what should i do if i want to access to each column data separated from each other.

how can i separate columns and access them in my block diagram?


Depends what you mean by "access". I am already "accessing" the data structure inside the event structure, so follow that pattern.

 

You can always index out and unbundle. Here's one possibility:

 

altenbach_0-1587830813197.png

 

Of course if the rest of the code is aware of the data structures, you might not need any of that.

0 Kudos
Message 8 of 11
(2,130 Views)

yes i meant index out and unbundle .

this code working but when i add numbers to one column  same indexes of other columns become 0 . what to do to avoid this? 

 

0 Kudos
Message 9 of 11
(2,125 Views)
Solution
Accepted by topic author ehsan75

@ehsan75 wrote:

this code working but when i add numbers to one column  same indexes of other columns become 0 . what to do to avoid this? 

 


Since 2D arrays cannot be ragged, LabVIEW will pad to the longest. Just index out the cluster array and unbundle each separately if you like that better.

 

altenbach_0-1587846824242.png

 

As I said, operate on the data in the structure. No need to "extract" anything, except maybe at the end for saving.

 

0 Kudos
Message 10 of 11
(2,100 Views)