LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Plotting Iterations of a subVI

Solved!
Go to solution

I need to plot iterations of a subVI over a finite range of iterations and retain the old data on the plot. The subVI takes the inputs and runs them through the following calculation:

eallder_0-1587247933928.png

The value of R_2 is constant at 470 ohm, V_in is constant @ 4V, and the variable B is constant at 50. The only input into the subVI that should vary is R_photo, which should be between 5-1000 ohm. Although the Waveform Graph does update if I run the VI and start changing variables, I'm pretty sure it should not be graphing a straight line. The X-Y Graph does not display anything at all.

 

This is my VI:

eallder_1-1587248339280.png

 

And this is the subVI:

 

eallder_2-1587248436619.png

 

At a later point, I am also going to want to add a plot of the sensitivity (Lumens/ohms).

 

Download All
0 Kudos
Message 1 of 20
(2,904 Views)

You are not understanding shift registers. If you want to build your array in a shift register, i.e. add the new element to the array coming from the previous iteration coming out of the left shift register terminal. There are plenty of examples in the forum how to do that.

 

Even simpler: remove the wait and autoindex at the right loop boundaries (no shift registers needed). You don't really need to see anything during the loop, right. Also, remove the wait.

 

(Also, since you know the number of iterations before the loop starts, you need a FOR loop, not a while loop. All your terminals should be orange)

0 Kudos
Message 2 of 20
(2,869 Views)

I've gotten the basic function and plot to work:

 

eallder_0-1587315863084.png

 

Now I'm trying to figure out how to take the derivative of the first graph and plot it as a second graph.

0 Kudos
Message 3 of 20
(2,815 Views)

Good. Now it's time to simplify.

 

  • You don't need the lower shift register, just do one "+1" before the loop, then add [i] from the iteration terminal inside the loop.
  • You don't need any express VIs and dyamic data (yuk!). XY graphs understand a variety of datatypes, simplest is a complex 1D array.
  • To take the derivative of Y, you can just get the data from the relevant output tunnel. No need to take a detour over[ a 2D array, convert to dynamic data, convert to a 1D array]. Very convoluted!
  • Resistances (and similar) are NOT integers, because a resistance is not countable, even if you simplify it to whole numbers. All your math is DBL, leading to coercions and unnecessary datacopies in memory. None of your math should involve anything blue.
  • Your indicator inside the loop is pointless unless the loop runs very slowly. All you'll see is the final value, but updating the indicator will slightly slow down your loop.
  • Not sure what's wrong with your screen capture, but it does not show the connection from x to the subVI.
  • If you attach your final code, I will show you how to simplify it. I am pretty sure it can be dome without any big loop.
  • Most of the operations in your subVI are always the same. No need to repeat them almost 100 times.
  • ...
0 Kudos
Message 4 of 20
(2,807 Views)

This is my code so far....

0 Kudos
Message 5 of 20
(2,805 Views)
Solution
Accepted by topic author eallder

Your derivative is more complicated, because dx is NOT constant. Here's what I would do: (just simple pairwise difference).

 

(The complex array has RE" x, IM:y, so if you subtract an array shifted by one, you get RE: dx and IM:dy and it is easy to approximately calculate dy/dx) 

 

 

altenbach_0-1587320959757.png

 

 

0 Kudos
Message 6 of 20
(2,788 Views)

Got it working...thank you! What is the best way to analyze the data from the Sensitivity graph? Say if I wanted to find the sensitivity at a specific number of lumens or determine the corresponding number of lumens from a certain point on the sensitivity graph? When I try to wire the data that is being plugged into the XY Graphs to a Write to Measurement File Express it doesn't work. Is it because it is a complex double?

 

eallder_0-1587326156876.png

 

0 Kudos
Message 7 of 20
(2,773 Views)

Well,

  • writing to a file requires a 2D array, instead.
  • You can convert your data to a array of points and use "interpolate array" to find the Y for an arbitrary x-value (make sure the x values are non-descending, of course)
0 Kudos
Message 8 of 20
(2,770 Views)

@altenbach wrote:
  • writing to a file requires a 2D array, instead.

Here's how to write a file with three tab delimited columns:

 

altenbach_0-1587330626122.png

 

0 Kudos
Message 9 of 20
(2,750 Views)

I got the wires to work to the Lumens per Ohm file express, but the file is only writing data for one x and one y value (the final one), even though I wired it up exactly like the Lumens vs Ohms above it. Also, why would I need to inerpolate the sensitivity when the sensitivity is already the derivative of the Lumens vs Ohms graph? The y-value of the Sensitivity Graph should be the slope of the Lumens vs Ohms graph.

 

eallder_0-1587330764676.png

 

0 Kudos
Message 10 of 20
(2,749 Views)