LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Building a Data Array in a SubVI

Solved!
Go to solution

OK first off, I'll say I am extremely new to LabVIEW.  I only started using it last week.  I am used to other programming languages so if I use some terminology that is not common to LabVIEW, I apologize.

 

What I am trying to do is collect temperature data and determine when it reaches steady state.  I am collecting data from a USB thermocouple DAQ in a for loop with a user defined number of iterations.  Each one of those iterations goes into an array.  The mean and standard deviation are calculated from this array.  Everything I have said is done inside of a while loop and once the standard deviation is low enough the while loop is terminated.

 

This works perfectly, but and there is always a but, I wanted to turn the array building, averaging, and standard deviation calculations into a subVI so that I can use this other times as steady state is a big part of what I test.  Also that way I don't have to have the data array show up on the front panel.  The issue I have found is trying to pass the DAQ data into the subVI.

 

Any help doing this or any suggestions on a more elegant way to determine steady state are greatly appreciated.  I have attached the VI in its intact form and a jpeg of it with the part I hope to put into a subVI boxed in red.  Hope this is enough information and if you have any questions, concerns, or suggestions feel free to post.  Thank you.

 

- Kyle

 

 

Taking and Graphing Temperature Question.JPG

0 Kudos
Message 1 of 6
(2,988 Views)
Solution
Accepted by kgould

You are taking a single measurment per FOR loop iteration, so you should convert the dynamic data to a single scalar instead of an array. Now you end up with a 1D array after the for loop and all that reshape mess is no longer needed. All you nead is the subVI for SD and mean that ships with LabVIEW and thus you already have.

 

You have a lot of coercions. "Iterations" and "numeric" should be I32 (right-click...representation...I32)

 

That rube goldberg comparison sequence is silly. All you need is a single comparison "SD<0.005" and wire the output to the loop termination condition. (btw, there is also a primitive for "<0"). 

 

Seems silly to write all raw numbers to a file every 10ms. It is probably sufficient to log the "means" to a file.

 

Why do you use single point acquisition and a FOR loop. Can't you do a hardware timed acquisition with N points and a given dT, eliminating the FOR loop entirely?

0 Kudos
Message 2 of 6
(2,982 Views)

Hi Kgould,

 

If you want to create a sub VI then all you need to do is highlight the bit of code you want to turn into the sub VI then go to edit > create sub VI and the sub Vi will be created.  I have done this and attached the files.  The array indicator and numeric indicators need to stay external to the sub VI as they are inputs to the subVI.  Hope this helps please post back if this does not answer your question.

 

 

Matt Surridge

National Instruments
Download All
0 Kudos
Message 3 of 6
(2,981 Views)

@kgould wrote:

This works perfectly, but and there is always a but, I wanted to turn the array building, averaging, and standard deviation calculations into a subVI so that I can use this other times as steady state is a big part of what I test.


Kyle, If you really think you need a mean&SD for a 2D array, I would recommend to go back to basics, e.g. as follows:

 

0 Kudos
Message 4 of 6
(2,970 Views)

@altenbach wrote:

You are taking a single measurment per FOR loop iteration, so you should convert the dynamic data to a single scalar instead of an array. Now you end up with a 1D array after the for loop and all that reshape mess is no longer needed. All you nead is the subVI for SD and mean that ships with LabVIEW and thus you already have.

 

You have a lot of coercions. "Iterations" and "numeric" should be I32 (right-click...representation...I32)

 

That rube goldberg comparison sequence is silly. All you need is a single comparison "SD<0.005" and wire the output to the loop termination condition. (btw, there is also a primitive for "<0"). 

 

Seems silly to write all raw numbers to a file every 10ms. It is probably sufficient to log the "means" to a file.

 

Why do you use single point acquisition and a FOR loop. Can't you do a hardware timed acquisition with N points and a given dT, eliminating the FOR loop entirely?


 

OK I have done each one of the things you have suggested but there are some down sides for not having the for loop I have come to figure out.  First is that the graph does not update continuously as before.  It just updates after each batch of measurements which isn't all the bad.

 

Also I made it so that I am only writing the means to file now for each batch of measurements as you had suggested, but the issue is that now I do not have any time stamp on the measurements.  Is there an easy way to add this to the file?

 

My last question is about actually initiating the file.  I have it ask the user so that no data can accidently be saved ontop of other data and so that ever test would have the proper name, but now that I only log the mean at the end it takes it some time to prompt the user to name the file.  Is there anyway to get it to do this first?  I know there are ways to use open file -> write to file -> close file but I am only familiar with the all in one write to measurement file.

 

Thank you both for all the great answers and ideas.  This forum is very helpful and makes LabVIEW a much more approachable software for a novice like me.

 

- Kyle

 

Pared Down Taking and Graphing Temperature Question.JPG

0 Kudos
Message 5 of 6
(2,952 Views)

Nevermind I got it.  Thank you very much everyone for the help.  I am sure I will be back here again in the future.

 

- Kyle

0 Kudos
Message 6 of 6
(2,939 Views)