LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Building an Array

I have what is a probably a very basic question and need some direction on building an array.

 

I want to graph the following equation Y=a0+a1x+a2x^2. for values of x that are equally spaced at 1mSec. I can calculate Y, no problem but struggling with how to build an array of X & Y values that I can plot.

 

I have tried using a for loop and building an array within the loop and sending it to a waveform graph but end up with a crazy amount of plots. Not sure what I am doing wrong.

 

Thanks

Newbie

0 Kudos
Message 1 of 25
(3,227 Views)

Attach a snippet of what you have tried, an example dataset, and what you expect to see from the dataset.  And by snippet, I mean, click Edit -> Create VI Snippet from Selection. 

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 2 of 25
(3,220 Views)

Look at the help window of the graph indicator, or open the Help / Find Examples - Window, then type "graphs" into the search field. This guides you to the different datatypes a graph indicator accepts.

 

Btw. it is a difference between the graph and chart indicator

Greets, Dave
0 Kudos
Message 3 of 25
(3,217 Views)

I tried to first just create a simple random number for Y and increment x by 0.001 on each itteration of the for loop.

 

Here is the code

0 Kudos
Message 4 of 25
(3,193 Views)

Okay.  So now you have a 2-D array where column 0 is your "Y" random value.  Column 1 is your "X" value ( 0, .001, .002, .....)  (I would have swapped the inputs to the build array so that X is column 0 and Y is column 1.)

 

So now you should be able to figure out how to apply your equation to the X value to get your Y value.

 

 

0 Kudos
Message 5 of 25
(3,188 Views)

I swapped the array inputs as you suggested.

 

The part I am not getting, is the plot....here is the graph that is being generated. Do I need to generate the graph inside the for loop?

 

 

0 Kudos
Message 6 of 25
(3,183 Views)

Did you do what Dave suggested?  Look at the help file for the waveform graph and you will see the datatypes that are accepted and the resulting graph.  A 2D array results in multiple plots rather than a single plot. 

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 7 of 25
(3,164 Views)

Maybe an XY Graph is what you need?

 

Example_VI_BD.png

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 8 of 25
(3,157 Views)

Since your X values are evenly spaced, that suggests a waveform chart/graph would work.  If you want to do it within the loop, just use a waveform chart as that maintains the history of past points.  So just wire the Y value to a waveform chart.

0 Kudos
Message 9 of 25
(3,143 Views)

Hmmm....I am using a waveform graph in several other places inthe program and wanted to stick with that.

 

Rethinking here.....else where I am only plotting a 1D array, perhaps I do not need to generate the x values and the waveform will space them equally, which would allow me to compare them to other waveforms

0 Kudos
Message 10 of 25
(3,135 Views)