From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Best way to plot elements of a vector with waveform chart

Solved!
Go to solution

I'm trying to plot elements of two 3x1 array as they change with time.  The setup in the first image below works, but gives me a time axis in steps instead of real time.  I know I'm supposed to turn these arrays into waveforms and link them to a time, but I'm having trouble figuring it out.

 

If I create a waveform by wiring the array and current time into a build waveform VI (shown in the second picture), the resulting chart isn't correct.  It interprets the three elements of the vector as three points on the chart, and then changes all three at every time step (so that you only see three points at a time).  I attempted to make a 2D array (a 1x3 array) with reshape array, but labview was not happy about that and gave me an error on the wire connected to the Y terminal of the waveform VI (saying the 2D array didn't match the type of the terminal).

 

At this point I'm about to break out all the elements of the vectors as separate waveforms, then hook them all back up into an array of waveforms, then wire them to the chart.  It seems like there should be an easier way for me to do this.  Is there?  I may want to do this with an 8x1 or even a 30x1 vector in the future, and it just seems crazy to have to make that many separate waveforms in order to add time to the chart.  😞

Download All
0 Kudos
Message 1 of 10
(4,080 Views)

Attach your VI instead of truncated pictures.

 

What's the purpose of the picture with "array to cluster". You don't seem to mention that.

To have x in correct time units, you can set dt via a property node. No waveform needed.

0 Kudos
Message 2 of 10
(4,071 Views)

Hi ben,

 

you forgot to define a dt of the waveform…

 

Are these 3 elements in your 1D array a signal (aka plot) in the chart? Or are these 3 elements one sample of 3 different plots? As you converted the arrays to clusters it seems each element belongs to a different plot. If this is the case then you have to put each element in its own waveform…

There surely are better ways to collect samples and display them - but you don't show the whole VI, just a small part of it!

 

(A 1D array just has 3 elements, an array with 3×1 elements is a 2D array!)

 

Best regards,
GerdW


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

Here is a simplified version of my VI.  All of the constants are user inputs and may change at runtime.  The array to cluster is my first attempt at plotting the information (I mentioned "first picture" in my original post).  It plots the data correctly, but instead of time I have a "counter."  I need to plot the data against absolute time.

 

As you can see, the loop does not repeat in a regular time interval, so I do not know what the "dt" will be.  Sorry about the 3x1 terminology - I'm coming from matlab where there is no distinction between a 1D array, 2D array, or matrix.  I think I've used each type in the attached VI correctly and out of necessity.

 

I'd like to plot each element of both arrays: each element should be a line on a chart that grows with each iteration of the loop.  

 

As I mentioned in my first post, creating a waveform for each element of the arrays will be cumbersome in the future when I have to do it for 8x or 30x element arrays.  It looks like that's the only solution, but it feels incorrect.  So I'm asking if I'm missing something simple that will let me plot an n-element array against time, with each element being it's own "plot" or line.

 

Is there anything that will let me plot an n-element array against time, with each element being it's own "plot" or line.

Download All
0 Kudos
Message 4 of 10
(4,023 Views)

I posted a reply but it looks like it was deleted??

 

Here's a sample.  The real thing is too big to post here.  The loop doesn't repeat at a predictable interval (so I don't know dt).  The behavior of the sample is correct, but instead of the "counter" on the x-axis, I want it to show absolute time.

 

Am I missing something simple that will let me plot an n-element array against time, with each element being it's own "plot" or line?  I'll have to do the same thing for a bigger array in the future, so making a separate waveform for each element will be very cumbersome.  Worst case I guess can put the waveform generation in a for loop...

Download All
0 Kudos
Message 5 of 10
(4,010 Views)
Solution
Accepted by topic author ben_psc

Hi ben,

 

see this:

check.png

As you are using a variable wait time in each iteration you need to build waveforms.

(A different option would be the XY graph then.)

 

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 6 of 10
(3,999 Views)

Hi Gerd.  Thanks for the help.  If you still have it, could you post the VI file?  I'm not familiar with the icons yet, so while I can guess at what they're doing, I can't access the help text.

0 Kudos
Message 7 of 10
(3,983 Views)

That's a VI snippet- you can drag/drop the image directly into LabVIEW and it'll throw in the code.

0 Kudos
Message 8 of 10
(3,974 Views)

Oh wow!  That's a pretty cool forum feature. Thanks.

0 Kudos
Message 9 of 10
(3,951 Views)

wrote:

Oh wow!  That's a pretty cool forum feature. Thanks.


It's a LabVIEW feature. Nothing to do with the forum The forum actually has problems with snippets 😄

0 Kudos
Message 10 of 10
(3,944 Views)