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 MathScript RT Module

cancel
Showing results for 
Search instead for 
Did you mean: 

XY Graph Labview

I have copied this block diagram directly from my textbook.  In the textbook, there aren't any errors that should arise, but in my diagram there is a problem at the bundle going into the XY Graph.  Any suggestions?

Screenshot (828).png

0 Kudos
Message 1 of 10
(5,843 Views)

To help us to help you, please attach the "code that fails", rather than a "picture of code that might or might not work".  This saves us time and effort (which we are "donating", for free).

 

Bob Schor

0 Kudos
Message 2 of 10
(5,821 Views)

Screenshot (833).png

0 Kudos
Message 3 of 10
(5,816 Views)

You attached another picture, one that partly obscures the picture causing the Error.  Assuming you are dealing with LabVIEW, you need to attach a file with the extension .vi, that is, LabVIEW code.  We cannot "edit" a Picture, we cannot (or, at least, I cannot) clearly see a Picture (the pixels are blurry), and when I right-click it, I cannot execute a Picture (to see the Error, also blurry, for myself).

 

Bob Schor

0 Kudos
Message 4 of 10
(5,806 Views)

I misunderstood. My mistake.

0 Kudos
Message 5 of 10
(5,805 Views)

Thank you!

 

As it happens, I don't have MathScript installed on my version of LabVIEW (I use LabVIEW, not Matlab).  But this is an opportunity to help you "learn LabVIEW", so bear with me.

 

First, look carefully at MathScript line 8.  There is, I believe, a "typo" in the formula, which will certainly produce a nonsensical answer, if not an out-right Error.

 

So how to do this the "LabVIEW" way:  use LabVIEW Structures and functions!  Here we go:

  1. Line 2 -- wire Sampling Frequency into the "Reciprocal" Function (on the Numeric Palette).  Now the output from this function is 1/(Sampling Frequency", which you can use whereever you need it.
  2. Line 7 -- Is the word "For" missing here?  What are you trying to do?  I think what you are doing is running a loop N times (and you know N).  Find the For loop on the Structure Palette, and wire Number of Samples to its "N" input.
  3. Look at how "t" is computed.  It basically is "Index of For Loop * Reciprocal of Sampling Frequency".  Well, the Reciprocal is living on a Wire from Step 1, and the Index is living inside the For loop in the little box with "i" inside it.  Bring the Reciprocal Wire into the For loop (notice you will get a "Filled-in Square tunnel" symbol when you do this) and use a Multiply function to multiply this by "i".
  4. Now complete the computation in MathScript Line 8 (after fixing the Error, of course).  You can find some useful Numerical Constants on the Numeric by opening the Mathematics Palette (look in the Palette list) under Elementary, Trigonometric.
  5. Bring the wire from the output of this computation (after multiplying by Amplitude, brought in, as was Frequency, on a Wire) out the right side of the For Loop.  Look at the Output Tunnel -- notice it should not be a filled in Square, but rather a Square with [] (a pair of square brackets, suggesting an Array) inside it.  Right-click the outside of this (Indexing) Tunnel and choose "Create Indicator.  Now, look at the Indicator on the Front Panel -- it should be a 1-dimensional Array, and should be what you want.

I am uncertain why your MathScript routine gave you a 2D Array, but then I'm not a MathScript user.  Try using LabVIEW, and see how easy (and logical) it is.

 

Bob Schor

 

0 Kudos
Message 6 of 10
(5,798 Views)

Thank you. I will try this out.  The reason we are using the Mathscript Structure in Labview is because the textbook had us do it that way.  I just asked our instructor and he said whatever way we can solve the issue, he is fine with.

0 Kudos
Message 7 of 10
(5,790 Views)

remove one of the "t"s from the last line. one is enough!

 

"x=A*sin(pi*f*t)" instead of x=A*sin(t*pi*f*t)

 

Also please fill controls with typical default data before attaching code so we can run it without having to guess:

 

altenbach_0-1584816650393.png

 

0 Kudos
Message 8 of 10
(5,766 Views)

@altenbach wrote:

remove one of the "t"s from the last line. one is enough!

 

"x=A*sin(pi*f*t)" instead of x=A*sin(t*pi*f*t)


Close, but only half a cigar (there's a clue buried in there ...).

 

BS

0 Kudos
Message 9 of 10
(5,753 Views)

@Bob_Schor wrote:

@altenbach wrote:

remove one of the "t"s from the last line. one is enough!

 

"x=A*sin(pi*f*t)" instead of x=A*sin(t*pi*f*t)


Close, but only half a cigar (there's a clue buried in there ...).

 


 

It gets rid of the error and outputs a 1D array as desired. Data looks like a sine function. Problem solved....

 

If different math is needed, that's out of my control 😉 I am not providing ashtrays! 😄

 

(But yes, using plain G instead of mathscript would turn is into a "fewliner".)

0 Kudos
Message 10 of 10
(5,747 Views)