LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Plotting a sine wave using arrays

Solved!
Go to solution

Hello! I wanted to see a graph plotted point by point so I built 2 arrays x and y to track the process, However, my attempt was unsuccessful. Here is what I did vs what my professor did but I don't understand why what I did was wrong. Can anyone please explain it a bit thoroughly so I have a good understanding of how to work with arrays. Thank you so much in advance!!

How I did it:

Laurenjpg_0-1636991571800.png

what my professor did:

 

Laurenjpg_3-1636991728478.png

 

(some more context:) Plotting on an XY-Graph point by point

In order to see the graph being plotted point by point, we have to send the x and y arrays to
the XY-graph at every increment.
For this reason we shall start with two empty arrays initializing the x and y values. At every iteration
we add the new values using insert to array to these arrays and plot them on the XY-graph.

 

 

0 Kudos
Message 1 of 4
(3,147 Views)
Solution
Accepted by topic author Lauren.jpg

@Lauren.jpg wrote:

Hello! I wanted to see a graph plotted point by point so I built 2 arrays x and y to track the process, However, my attempt was unsuccessful. Here is what I did vs what my professor did but I don't understand why what I did was wrong. Can anyone please explain it a bit thoroughly so I have a good understanding of how to work with arrays. Thank you so much in advance!!

How I did it:

Laurenjpg_0-1636991571800.png

what my professor did:

 

Laurenjpg_3-1636991728478.png

 

(some more context:) Plotting on an XY-Graph point by point

In order to see the graph being plotted point by point, we have to send the x and y arrays to
the XY-graph at every increment.
For this reason we shall start with two empty arrays initializing the x and y values. At every iteration
we add the new values using insert to array to these arrays and plot them on the XY-graph.

 

 


In your effort, you are creating a new array of one element with each iteration, for both the x and y axes and sending them to the graph.  I suspect you are seeing a single dot traversing a sine pattern.  What you need to do is find a way to add on the the end of the existing arrays, which is what your professor had done.

 

It is awkward to do it with an XY Graph because of this.  Your way would work for a chart, though.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 2 of 4
(3,123 Views)

Thank you so much!! That was very informative!! I have a few questions left:

>>why did we use an array constant instead of an array indicator?And why is it placed outside the loop?

>>I'm also facing issues with understanding the wiring of the index in insert array.

 

Hope you can kindly clear up some of the confusion

Thank you so much in advance!!

0 Kudos
Message 3 of 4
(3,104 Views)

Hi Lauren,

 


@Lauren.jpg wrote:

1. why did we use an array constant instead of an array indicator?And why is it placed outside the loop?

2. I'm also facing issues with understanding the wiring of the index in insert array.


  1. You use the array constant to initialize the shift registers…
  2. I also have issues with those InsertIntoArray functions: most often they are used wrong! You should use BuildArray instead in your VI to append new samples to your arrays… (When you know the final array size before loop starts you should initialize the array to correct size and use ReplaceArraySubset. Or use autoindexing at loop border.)
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 4
(3,099 Views)