LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Use a Mathscript code which has both x and y data and produce it in a waveform

I have this MATLAB code:
 
t = (0:0.0000001:0.01);
f1 = 0.0011312*cos(2*pi*49400*t);
f2 = 0.003936*cos(2*pi*100*t);
H = (f1*f2);
x = ((2.93464*10^-10)*H);
ms = 1000;
M = ms (coth(x) - (1./x));
 
I want to plot it on Labview 8.0 as M vs. t with 'M' being Y-axis and 't' being X-axis.
 
I tried using MathScript to type the MATLAB code but when i add an output to it and connected it to a waveform, it does nothing....
 
Thanks,
K
0 Kudos
Message 1 of 4
(2,890 Views)
On Dec 9, 5:10 pm, Kris Matrix <x...@no.email> wrote:
> I have this MATLAB code:
> &nbsp;
> t = (0:0.0000001:0.01);f1 = 0.0011312*cos(2*pi*49400*t);f2 = 0.003936*cos(2*pi*100*t);H = (f1*f2);x = ((2.93464*10^-10)*H);ms = 1000;M = ms (coth(x) - (1./x));
> &nbsp;
> I want to plot it on Labview 8.0 as M vs. t with 'M' being Y-axis and 't' being X-axis.
> &nbsp;
> I tried using MathScript to type the MATLAB code but when i add an output to it and connected it to a waveform, it does nothing....
> &nbsp;
> Thanks,
> K

Two suggestions.
There maybe some exceptions but most of the time with Labview's Data
flow approach to programming you need to calculate all of your output
points before you pass the data to a waveform graph. How are you
accumulating your data?
Instead of using a Labview waveform graph to plot the data use a
Matlab plot command to plot the data. Once you can successfully plot
the data with a Matlab plot command then go onto the next step and try
to plot the data with a Labview waveform graph.

Howard
0 Kudos
Message 2 of 4
(2,870 Views)
Hi Kris,

It looks like there are a couple of errors in your MathScript code. This is probably why the outputs from your MathScript node are not getting any data. Try creating an indicator for the Error Out terminal on the bottom right corner of the node. Now when you run the VI you'll see an error with the multiplication on line 4. Once you fix that (either by transposing f2 if you want vector multiplication or by using the .* operator if you want elementwise multiplication), you'll see another error on line 7. I'm not sure what you're trying to do on that line, but MathScript interprets it as trying to extract an element of the 1x1 matrix "ms".

Let us know if you still have problems after fixing these two lines.

Also, if you're interested, there's a dedicated MathScript forum here:
http://forums.ni.com/ni/board?board.id=MathScript

Jesse
0 Kudos
Message 3 of 4
(2,861 Views)

K,

I think the problem may be in the syntax you are using.  f1 and f2 are both 1x100001 matrices.  When you try to multiply them together using "H=f1*f2" this is a matrix multiplication, and two 1xn matrices cannot multiplied together.  If you want to do elementwise multiplication so that H will also be a 1x100001 matrix, then you can use "H=f1.*f2".

One way to verify that this gives the correct results (x and M are both the right size), you can run the script in the MathScript window before using it inside a MathScript Node.

Chris

0 Kudos
Message 4 of 4
(2,858 Views)