LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

insert into array using for loop and display continuously

Solved!
Go to solution

Hi,

 

                I am trying to insert for loop loop itration values into two arrays and trying to plot using XY graph. I need values shouls be inserted one by one in each iteration. But at the end of iteration in array I am getting only last value.. can anyone help me?

0 Kudos
Message 1 of 13
(6,543 Views)

Hi ef,

 

did you try to debug that VI with highlighting and probes? You really should have to...

 

What do you expect when you create a new array on each iteration (by InitArray)?

What do you expect by inserting one element into that array?

What do you expect when you set the ExpressVI "Build XY graph" to "Delete data on each call"?

 

check.png

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 13
(6,536 Views)

Hi GerdW,

               

                    I tried your solution but no graph came. I asked this as part of my project. My real intention is to add values into array and plot it in real time. But by using your solution i will get array only after complete iteration of for loop. For each iteration insert some values into array without deleting the old value.. just add new element into next location. can you provide any idea?? 

 

Thanking you,

                 Manu

0 Kudos
Message 3 of 13
(6,526 Views)
Solution
Accepted by topic author ef.manu

Hi Manu,

 

use a shift register to store each array. Use BuildArray to prepend/append (not insert!) new values to the array!

Then you don't need to use an ExpressVI to create the graph, a simple bundle node (as shown in the context help) is sufficient to create a plot for an XY graph...

 

Example with just one array:

check.png

 

Keep in mind:

This is not (memory/CPU time) efficient to be used for long time data aquisition (resulting in big arrays). Use different approaches then...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 13
(6,521 Views)

Hi Gerd,

 

           I am very thankful to you for giving great solution, saving my time and spending your time for me. I was struck in this problem for few hours. 

 

 

                                                         Thanking you,

                                                                    Manu

                   

0 Kudos
Message 5 of 13
(6,513 Views)

Hi ef,

 

you really should not create double post for the same question/topic!

 

All you do is keep people busy to provide the same answer in several places!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 13
(6,492 Views)

Hi everyone,

     I am trying to write datas generated by For Loop into an initialized array (8*8). There are 3 For Loops. I want the datas of each iteration to be inputted in the initialized array one by one, but actually at the end of iterations I only got the last values of iteration (the latter values covered the former ones), so I got  the array of 2*8. Please see the attached VI.

    I am using Labview 2012.

    Thanks so much!

    Yimi

0 Kudos
Message 7 of 13
(6,355 Views)

Yimi168 wrote:

     I am trying to write datas generated by For Loop into an initialized array (8*8). There are 3 For Loops. I want the datas of each iteration to be inputted in the initialized array one by one, but actually at the end of iterations I only got the last values of iteration (the latter values covered the former ones), so I got  the array of 2*8. Please see the attached VI.


Why not use two 8x FOR loops instead. See attached.

 

Modify as needed. If you also want to see the intensity graph update in real time, it's terminal would belong inside the inner FOR loop, of course.

 

(You have a serious overuse of sequence structures and local variables. None are needed. You are also not properly incrementing the indices of the insert point. And please don't maximise the front panel to the screen, that is just annoying).

0 Kudos
Message 8 of 13
(6,341 Views)

Thank you very much, Altenbach.

Just as you said, I overused the sequence structures and local variables. Thanks a lot to learn from you.

But this vi is a simplified vi of my problem. In the second loop of my original Labview program, there is another sequence structure where my third loop is. Actually, the datas generated are more complicated than the random generator. I just want to know if it is possible to solve my problem in my case, I want the datas of each iteration to be inputted in the initialized array one by one, not covered by  datas of the next iteration.

Thanks a lot!

0 Kudos
Message 9 of 13
(6,324 Views)

Yimi168 wrote:

But this vi is a simplified vi of my problem. In the second loop of my original Labview program, there is another sequence structure where my third loop is. Actually, the datas generated are more complicated than the random generator. I just want to know if it is possible to solve my problem in my case, I want the datas of each iteration to be inputted in the initialized array one by one, not covered by  datas of the next iteration.


I don't like text descriptions, because they are too ambiguous. Please attach the actual code instead.

 

If you look at your math to calculate the insert point, you see that you never increment the row index. You need to change the math based on the value of all iteration terminals. That's it!

 

Also note that your code does NOT replace elements one-by-one as you say, but two at a time (place a small wait to see what's happening!)

0 Kudos
Message 10 of 13
(6,318 Views)