Showing results for 
Search instead for 
Did you mean: 

XY Graph In a non linear fashion

Hi, I've been looking through the boards and I've been having some trouble finding a solution to this problem (Maybe I'm missing the dancing bear). I am bringing in xy points and graphing them and I'm trying to find a way to plot them in a non-linear fashion. Essentially the customer needs a nice curve fit and I'm having problems figuring that out. Again, maybe it's incredibly simple. I'm using an XY graph. 


I've included my VI. Right now I'm not dynamically changing the plot points - I was just playing around to figure out the XY graph. I have it plotting, but I can't figure out how to make it curve fit. Any suggestions would be greatly appreciated. Thank you!

0 Kudos
Message 1 of 11

I don't understand what you mean by a non-linear fashion.

The data determines what the graph looks like.

0 Kudos
Message 2 of 11

LabVIEW has tools for curve fitting. Graphs have built-in logarithmic mapping. For any other type of curve you need to program it yourself.


What kind of curve is required? Your VI only shows 3 points. You can fit almost anything except a straight line to that.


Your VI has several things which can probably be done much more efficiently, but it may be better to address those as a separate issue.



Message 3 of 11

Well I am incredibly new to Labview. I'm doing this as an internship and it is my first time ever doing anything with Labview or anything like it. In one of the examples I've been given by the company I'm doing it for the end result has 14 points which increase very slowly, however I don't want them in a linear fashion. Though I did not know the graphs had built in logarithmic mapping. This could very well be what I need.


I understand the VI is probably incredibly embarassing to someone who has had more experience with Labview, however, as I said unfortunately I have very little experience with really anything other than college courses. I apologize for the inner pain you must feel by looking at this, but I do appreciate your help. The few questions I've asked here I've gotten very helpful responses and it seems like a great forum. 

0 Kudos
Message 4 of 11

We like to help people learn to use LabVIEW effectively. So please continue to ask questions as they occur to you.


NI has online tutorials to help you get started with LV. If you have not had any formal training, take a few hours to work through those tutorials.  You will save far more time in the long run than it takes to go through the tutorials.


General comments:

- Avoid inifiite loops - loops which never stop. The Gage 1 loop at the bottom can only be stopped by aborting the program. "Using the Abort button to stop a VI is like using a tree to stop a car. It works but may have unintended consequences!"   In this case the serial port is never closed which makes it unavailable to any other user.

-  Avoid local variables. They are prone to race conditions, are much slower than wires, and may make extra copies of the data. In LabVIEW the wire is the variable. A local variable is effectively an unwired connection to a control or indicator, not the variable.

- Avoid very long Waits. You have several places where waits of multiple minutes occur. While those waits are occurring, that portion of the code is blocked (although parallel code may run). Often it is better to have short waits in a loop with a counter and a check to see if anything else has happened such as the user pressing a Pause button. With a 100 ms wait and a count to 600 you get a one minute wait which can be interrupted within 0.1 second if necessary.

- Keep the size of the block diagram to the size of one screen. If you have to scroll all araound to see the code it is difficult to tell what is going on. A state machine to do all this will be about the size of your hand.


You do a nice job of documenting what different sections of the code do.



Message 5 of 11

I appreciate it. When I first started this project about a week and a half ago, I despied Labview but as I get more used to it (nowhere near competent, just less bad) I realize it's not bad - just so different from what I know. It's just a brand new concept to me to not be writing the code. I understand Labview can implement written code, but I got thrown into this trial by fire and this seemed like the best way to get into it and try to get this done. A few questions concerning your comments.


The local variables.. I didn't think it was the best way to do it but how do I use the Position in other parts of the VI since it's in a while loop? I used the variables because I couldn't figure out how it was to break out of the loop and go to other places - it wouldn't leave.


The long waits is a nice thing to know, just another concept of Labview that really wouldn't appear in the programming that I've learned. The only reason the block diagram is so big is because I'm not at all familiar with Labview and it was easier for me to follow that way. It just seemed to me like the best way to do it as it slightly resembles the concept of procedurial programming in my mind. It was easier for me to see the step by step that way and understand it. Incompetence fuels everything sometimes.


Essentially what I need with the graph is similiar to an exponential curve fit. It's incredibly aggravating to me since I know all the calculus and could do it, but I'm just not sure how to do it in Labview. My experience with Labview are actually opposite of programming. In programming, I think the general concensus is that the difficult part is solving the problem, not implementing the code, however with Labview I find it's easy to solve the problem - I know what I need to do I just don't know how to do it. Again, I appreciate your help. 



0 Kudos
Message 6 of 11

It is difficult to get data out of a running loop. For most situations the preferred solution is to use a queue. Look at the Producer/Consumer Design Patterns and examples which come with LV.


Consider your while loop with the Equal2 Express VI. It has two Position local variables. LabVIEW uses a dataflow paradigm rather than the line by line sequential behavior of many text-based languages. This means that any node may execute as soon as data is available at its inputs and that no data is available at its outputs until all code within the node has completed. As soon as that while loop starts executing both local variables are read immediately.Then the sequence structure waits for one minute. At the end of the wait the data is passed to the Equal2 VI. Unless the value of Position changed within the few nanoseconds between the evaluation of the two local variables both inputs to Equal2 will be identical. They absolutely will not represent the values one minute apart. Not until the loop begins its next iteration will newer values be available.


You can use subVIs to encapsulate logically connected sections of code. With appropriate names and icons you can create compact but well documented main block diagrams.




Essentially what I need with the graph is similiar to an exponential curve fit. It's incredibly aggravating to me since I know all the calculus and could do it, but I'm just not sure how to do it in Labview. My experience with Labview are actually opposite of programming. In programming, I think the general concensus is that the difficult part is solving the problem, not implementing the code, however with Labview I find it's easy to solve the problem - I know what I need to do I just don't know how to do it.



All programming, including LV requires knowing how to solve the problem. Once you understand the algorithm or procedure you want to implement - in any language - the coding is essentially a matter of learning the instruction set and syntax.  Because you apparently know how to define the process you want the program to execute, you will have little problem learning to program in LV.  Some tips: Always keep the Context Help window turned on while programming. It will show the name, icon, input/output connections and a brief description of any node, function, structure or subVI when you move the cursor over the icon. For most it has a link to Detailed Help. Spend a little time exploring the Functions palette just to get an idea of what is there and where it is. There is a Search capability in the Functions palette. It is not the most powerful search engine and looks for the name of the function or VI but can be helpful especially when you know what you want but do not know where it is. At a higher level use the Example Finder. The examples are complete, working VIs. You can use them as they are or make a copy (with a new name) and modify them to meet you specific needs.  


For your exponential scaling of the graphs look in Mathematics > Elementary & Special Functions > Exponential Functions.  Note that Mathematics is not the Numeric palette under Programming.  If you post your functional requirements, we can help you find what you need.


The attached VI shows how the Gage Stable? can be implemented without local variables. The Producer loop at the top allows you to manually enter a "Position" without needing all the external hardware. Note that the Gage Stable loop can be stopped anytime by pressing the STOP button on the front panel. It also stops when the positions are the same within +/-0.001 on two occasions 1 minute apart. Using exactly equal comparisons on flaoting point numbers is generally not a good idea because of the finite representation of numbers in binary. If you want to use the Express VI, choose the "Equal within tolerance" option rather than "Equal". Test is not a complete solution. The Producer loop can only be stopped manually even after the stability loop stops.  After you have looked at it, you may have questions. Feel free to ask. That is how you can learn.



Message 7 of 11

Well that's excellent to know about the gage. I suppose that would have really thrown off the program had I left it like that. Also, I know this is an ignorant thing, but I hadn't considered Sub-VIs. I was overwhelmed and it seemed to me like something that didn't need to be used, but now that I look at it they're essentially the functions of text based programming, which without functions text based programming is about the worst thing to ever happen to the world. It's like assembly at that point. I knew about the search, but it's really good to know about the Context Help window because everytime I needed to know the inputs I had to go to the advanced help or use the probe tool. I really appreciate the included VI of the gage - it'll help me a lot. I have a knowledge of queues but in C++ but I honestly didn't even consider them for this. Again, I was overwhelmed by LV and I was going for the most basic procedurial programming I could think of and make work. 

0 Kudos
Message 8 of 11

I currently have the position values and the corresponding temperature values in queues and I need to export them to an excel file for the user to save as their batch records. How is it possible to take those values out of the queue (obviously a simple dequeue in a loop so long as they're not empty) into an excel file? I'm having some trouble figuring this out.


Edit: I found the nice excel functions pallete which makes things a lot easier. 

0 Kudos
Message 9 of 11

Certainly, LV is a lot to learn all at once. But it would not be any different if you suddenly had to switch from C to Cobol.


A queue should only be dequeued in one place. If multiple parts of the program dequeue from the same queue, you have no way to know which element went where. With that caveat a dequeue in a loop is a good way to go.  You can set a timeout and monitor the timed out? result to see when the queue is empty. An alternative is to use Get Queue Status amd set return elements? True. This will generate an array containing all the elements of the queue (at that time) without removing them from the queue. If Enqueue and Dequeue operations are going on elsewhere in the program at the same time (LV is inherently parallel), the array of queue elements can change in inpredictable ways.  If you are done with the queue or the data in it you can use Flush Queue or Release Queue to get the remaining data.


The Example Finder has some queue examples under Optimizing Applications >> Synchronizing Tasks which may be helpful.  There are also examples for File I/O under Fundamentals.





0 Kudos
Message 10 of 11