LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How plot a quadratic function using slide bar as x values?

Solved!
Go to solution

Hi, I'm a learning user of LabVIEW. I would like to graph the function y(x)=x*x, but using the values of the slide bar control as x axis in a while loop. I want to graph the y(x) function as a continuous line and a different cursor to highlight the value of the slide bar. I know that using property nodes the maximum and minimum values, as well as the increment of the slide bar can be fixed. However, I haven't found useful examples online. I've attached a screenshot of the desired graph (edited using paint).

0 Kudos
Message 1 of 8
(4,013 Views)

That looks like two plots on an XY graph to me.

 

Plot 1:.  Line, no points, consists of the calculation of Y's based on a ramp of X's.  Data can be calculated once at the beginning of the program.

Plot 2:.  Points, no line.  Consists of the calculation of a single Y based on the X value in the slide.  That data is point is calculated anytime the control changes, and the two plots merged and plotted on the graph.  This would be a good use for an event structure acting on the value change event of the slide control.

Message 2 of 8
(4,005 Views)

Thanks for your easy to understand explanation. The problem that I'm facing is that the XY graph requires a cluster (cluster or array?) as an input, and I get only one element from the slide control.

0 Kudos
Message 3 of 8
(3,996 Views)

Look in LabVIEW Help or Examples for XY Graph that tells you a few different ways  you can wire data to the XY graph.

 

If you have a single value that needs to be an array, just use Build Array to create a 1 element 1-D array.

If you need a cluster, use Bundle or Bundle by Name.

 

If you still get stuck, attach your VI with what you've gotten so far.

0 Kudos
Message 4 of 8
(3,970 Views)

Thanks, I have some problems trying to merge both graphs, because they are different types of data. It seems a silly problem, but I don't know to figure it out. 

0 Kudos
Message 5 of 8
(3,900 Views)

Hi Dranek,

 

in the first frame you create a cluster of 2 1D-arrays, in the event you create a cluster of 2 scalars. Then you want to build an array of both, which will not work due to different datatypes!

 

Both plots need to use the same datatype. A XY graph accepts

- (an array of) a cluster of 2 1D arrays

- an array of clusters of 2 scalars

- an array of complex numbers

Did you read the context help of the XY graph? It explains how to build one plot and it shows how to build an array of plots…

 

Side note: why did you use a sequence structure at all? Everything follows DATAFLOW…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 8
(3,897 Views)
Solution
Accepted by topic author Dranek

See the attached VI.

 

1.  Fixed the data type issue by adding the build array like I talked about.

2.  Got rid of the unneeded sequence structure.

3.  Replaced the formula node with the X^2 LabVIEW primitive.

4.  Added the Ramp pattern function I talked about to create the full curve.  (The local variable of the slide did nothing but give you a 1 point curve at whatever value the slide was when the VI started!)

Message 7 of 8
(3,890 Views)

Thank you! This example will help me to improve the plotting of my project. I'm trying to plot an instantaneous measurement plus my desired response in the same graph. I know that that I was doing was completely wrong, but it is hard to learn by yourself if you couldn't find examples related to your problem. Thank you for your patience and help!

0 Kudos
Message 8 of 8
(3,884 Views)