LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to plot previous and present graphs in xy graph??

Hello friends!

 

I am designing a program for automatic power current measurement in labview! I am actually stuck with a small problem! I want to plot a previous and present plot in one single xy graph. I have attached my labview program. Actually I am able to plot preious plots also but only when the history length is more than the number of loop iterations. But i need just the previous and the present plots i.e the history should only be 2! In that case, the previous plot is being erased after completion of 2 iterations and then only the present graph is plotted and displayed! Please check the logic in the last sequence! If anything is missing please suggest me! 

 

Thanx!

Vinay

0 Kudos
Message 1 of 4
(5,456 Views)

Hello,

 

I took a quick look at your code, and I have a two somewhat independent thoughts for you.  The first applies to LabVIEW programming in general, and the latter is focused on some details of XY graph data.

 

General LabVIEW Programming Suggestions

I noticed that you're using sequence structures and local variables (and in this case a use case of the bundle array function) where the code would be more efficiently compiled if you went with a different approach.  

 

I don't mean to be super-critical here by any means - it's fairly common when people first begin programming - especially with previous text-based programming experience - to travel similar paths.  That and/or not having a chance to get some formal training are not uncommon reasons for this.  Without launching into a full code review of sorts, here are a few pointers along those lines based on an admittedly cursory look at your code:

 

  • you should try to use dataflow to control the execution order of your code (instead of sequence frames),
  • try shift registers (in this case) perhaps to maintain previous and new values in your loop where you currently have variables,
  • try pre-allocating an array of appropriate size and use Replace Array Subset to build up arrays vs using the Build Array function on every iteration (which can cause de/reallocations as the array grows - this is a memory and performance hit).
Managing XY Graph Data
I'm exactly sure if you're trying to plot previous and current data in the same plot (ie. keep a history in some existing number of plots) OR if you're going for adding new plots over time to your graph.  Either way, this game boils down to understanding the data type accepted by the XY graph, and maintaining that data structure with relevant data each time you update the graph.  
Generally for an XY Graph, a "plot" is represented in data by a cluster of two arrays (x coordinates and y coordinates respectively).  Multiple plots then are achieved by creating an array of those plots/clusters.
With that in mind:
  • Static Number of Plots with Growing Data - if this is what you need, you will want to basically unpack and repack the plot/cluster to add more data to it.  Adding more data basically means appending data to the x and y point arrays inside that plot/cluster.
  • Adding New Plots and Keeping Old Plots - in this case you'll be growing the size of the array of "plots".  The plots will still all be clusters containing the two arrays, again for X and Y points respectively.
It'll probably take a bit of a time investment to get comfortable with this - sort of spans a couple layers of development, from LabVIEW programming general/efficiency/techniques to specific details of managing data for an XY graph.  But if you'll be using this stuff, it'll certainly be worth the time.
Hope this helps!

 

Best,
JLS
Sixclear
Message 2 of 4
(5,441 Views)

Hi! Thank aou so much for such a detailed explanation. But I am sorry that I dint help me solve my problem! If run the program once, a graph is plotted at the end. When I again run the program the previous graph should exist as well as the new graph should be plotted over it. Please correct my program or else please tell me where exactly should the changes be made inorder to achieve the desired result!

 

Thanks!

Vinay

0 Kudos
Message 3 of 4
(5,420 Views)

Hi Vinay,

 

It's the multiple runs of your program that is causing the issue here.  There is a method for retaining values in LabVIEW across multiple runs of a VI however.

 

Direct Approach

 

  • To do this, you can use an unititalized shift register.  You'll certainly find good resources on this in the NI community and developer zone in general, but the basic idea is that you create a shift register on, say, a while loop without initializing the shift register from outside the while loop.
  • This causes the shift register to take the first value assigned to it inside the loop as well as retain values across multiple runs of your VI.
  • This is at the heart of many code modules which provide an interface (set of operations) to some data, and manage that data across multiple calls to that subVI throughout a program.  The multiple calls to the subVI in that case is analagous to the multiple runs/calls to your VI in your case.
  • I'll have to leave the programming of this up to you, but you can take advantage of this concept if you truly need to retain data across multiple runs of your VI.

 


Additional Structure Approach

 

  • Another approach would be to have your VI actually continue running and maintain the data over time.
  • Even if you needed it to actually acquire/present data based on manual operations (ex. you click a button), you could still allow your VI to run and present new, accummulating data.
  • One piece of this puzzle might be an event structure which can trap and handle your button click (perhaps your "manual acquire" button).
  • In general, you'd use the techniques described in my first reply to hold and manage the growing data set over time - those techniques actually apply to the approach above as well.
I hope this helps!

 

Best,
JLS
Sixclear
0 Kudos
Message 4 of 4
(5,411 Views)