LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem building multiple arrays of XY data clusters into arrays inside of a for loop

Solved!
Go to solution

Hello,


I am converting a recording program to a new design (attached as "TC Reader.llb") and I have run into a problem with the graph.  In the original design (attached as "OLD TC Reader.llb"), data was taken from up to 16 channels on a thermocouple reader (NI-ENET 9213).  All of the data collection and graphing was hard-wired 16x, so I am re-writing it to work with loops.

 

I resolved one problem (sort of) in which the for loop would apparently not execute when "enable indexing" was selected for the inputs to the loop.  It runs just fine with the setup I have now, even though one of the inputs is indexed.  I mention this because if that worked it might help solve the problem at hand.  I am not sure if I am doing something wrong or if it's a LV bug.  

 

The problem at hand:  I am having trouble building the data needed for the xy graphs.  The necessary data type is: 1-d array of: cluster of 1 element: XY chart data (1D array): new coordinates (cluster of 2 elements): [x, y] elements

 

That is rather complicated, but it works in the original design.  In the new design I can't use the original recipe for building a cluster array due to the for loop.  I have tried a number of alternatives all afternoon without figuring out something that works.  The file is a bit messy because it has a handful of diagnostic stuff.  The top-most graph is sort of working, but all of the data is being put into one wave.  For instance, the loop is presently set to read 3 of the 16 channels.   2 of those channels are reading around 25C and one is around 80C.  The output on the graph includes all of the data together in the order it was taken, so it has a sawtooth pattern going back and forth between 25 and 80C.  I am basically re-assembling the data incorrectly.  Otherwise the file-logging portion of the program appears to be working well.    

 

Any help would be most appreciated.  

 

 

As an aside, I really wish LV would handle XY data in a similar fashion as graphing programs such as Igor Pro.....    

Download All
0 Kudos
Message 1 of 7
(6,195 Views)

Hi there,

 

It looks like you've made some great progress so far.  For building the correct data type for the xy graphs I would look at a certain example.  In Labview go to Help >> Find Examples.  Once the example finder is up search for "xy" in the search bar.  Once there you should see a "XY Graph.vi" example which should help to show a few different ways of building the correct data type.

Scott A
SSP Product Manager
National Instruments
0 Kudos
Message 2 of 7
(6,172 Views)

Thanks for pointing to those examples.  However, they are helpful only for a problem I have already solved.  In all of the XY examples I see, the loops are for building data into an XY graph.  In my program, that is successfully achieve by the outer loop which runs in real-time until you hit "stop".  The problem I am having is properly combining those XY datasets.

 

In the original design, the 16 plots were combined by using the "build cluster array" block.  I don't think I can use that in this design.  Instead I have tried to use "build array" both inside and outside of the loop.  The best I have been able to achieve is to dump all of the data into a single "plot".  That is, there should be 16 elements to the outermost array - each of which is an XY graph.  Instead, index 0 of the array contains contributions from all of the "plots", while indices 1 through 15 are empty.  

 

I am guessing (hoping) there is an easy fix, however I am not seeing what it is at this time. 

 

Regards,
Scott 

0 Kudos
Message 3 of 7
(6,154 Views)

Are you trying to have your XY Graph look like this:

xy graph.PNG

With multiple plots showing up on one graph?

 

Or would you like each plot to have its own graph?

 

Is each plot coming out of the loop as an array, a cluster, or something else?

 

Scott A
SSP Product Manager
National Instruments
0 Kudos
Message 4 of 7
(6,139 Views)

I'm trying to get all of the plots onto one XY graph as you show above (to have only one graph).  In the code I posted, the for loop should run 16 times (I had it set to 3 while I was checking various things).

 

The output of each iteration of the for loop is as follows:  XY chart data (1D array): new coordinates (cluster of 2 elements): [x, y] elements

 

I believe that what I need to do is to take that output, turn it into a cluster, and then build a cluster array.  That approach worked in the original design because all 16 inputs were wired directly into a "build cluster array".  

 

 

 

0 Kudos
Message 5 of 7
(6,135 Views)

The XY graph can take a variety of input formats.  One (undocumented) format that may work easily for you is to combine your X and Y values into a complex number (Re/Im To Complex) and simply build a 1D array of these complex numbers.  Saves a lot of fussing around with clusters.

 

ComplexXY.png

 

If you need multiple graphs, put each complete XY plot into a cluster, and then build an array of those:

 

ComplexXYArray.png

 

 

Note: credit to Christian Altenbach (I think) for pointing this out many years back.

Message 6 of 7
(6,130 Views)
Solution
Accepted by topic author SAMullin

 

Picture1.png

 

Thanks Greg.  Your advice eventually led me to the correct solution.  I think the path of using a complex number to represent the data might have worked, I just didn't make it that far (though I was concerned that the XY graph would not want to display the x-axis as "time" if the number was imaginary, I never got that far).  

 

The breakdown with that approach came when I hit the xy chart-buffer sub-vi.  The sub-vi was made for handling clusters, so in the process of opening it up to convert it over, I realized that the buffer was causing my problems.  I had reached a point where the data was plotting, but all of it was being duplicated 16x and being dumped into one large array.  I believe the problem was that the buffer was using a local varaible for the XY data that was using data from the previous execution.  In this design, the previous execution contained data from the previous loops, so all of the data was being concatenated together.  I altered the sub-vi to take an array as an input instead of referencing its own output.  This seems to have worked like a charm and now the program is working.  

 

 

I was thinking about this problem for awhile, and I realized that using a cluster and using a complex number in the way you described are essentially the same thing.  The important thing for me to realize was that the "cluster" is simply a way to get around the fact that you can't have "arrays of arrays", so it is possible to "bundle" and "unbundle" a cluster that essentially only contains 1 element, which in my case is an array of many other elements (XY data points).  

 

 

I found all of this rather confusing, so I will post an explanation that makes sense to me in the hopes that someone will eventually find this insightful:  

 

In the final working design (attached), the XY data is bundled together (so each data point is one cluster).  Then, those clusters are strung together into a 1D array (which contains all of the data for a single plot).   In order to send those to the XY graph, each 1D array must be "bundled" to create a cluster of 1 element (that being the entire 1D array of XY data points).  After the bundling operation, the data goes straight out of the loop (with indexing allowed) to the graph.  Then I used a feedback node to take all of that data back into the loop where it is subsequently indexed to the correct "plot" for the next data point to be appended inside of the buffer sub-vi.

 

The attached program is a data logger for the 16-channel thermocouple reader.  With slight modifications to the number of inner loop iterations and array sizes it will work for any device that has input from multiple channels.  

 

There is one nagging problem that I can't figure out.  As I understand it, it should not be necessary to index the arrays as I have done.  However, when I remove the index array functions and simply allow indexing on the loop tunnels, the loop no longer executes and the entire program does nothing.  Any clarity on that would be most appreciated.  

 

0 Kudos
Message 7 of 7
(6,114 Views)