From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, 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: 

Same code gives different results in Matlab Script in Labview and Matlab

I am implemeting a Matlab code into a LabVIEW application using Matlab script. When I import the exactly same code to the Matlab Script in LabVIEW it gives a different result than it is in Matlab. This code is a simulation code including first kind bessel functions. Using LabVIEW 7.1 and Matlab R14 service pack 3.
0 Kudos
Message 1 of 22
(4,235 Views)
Is it only slightly different or complely wrong?
 
Error handling in a matlab script node is not very good. Have you at least hooked up the error output of the matlab script frame? Does it tell you anything?
0 Kudos
Message 2 of 22
(4,211 Views)
Hi iort,

Along with Altenbach's statement, can you provide me a simplified version of the .m script code you used that will reproduce this error? If we know what is expected and what is actually outputting we can determine internally what the problem is and how to fix it.

Also, have you tried the MathScript node in place of the Matlab script node?

Cheers.

| Michael K | Project Manager | LabVIEW R&D | National Instruments |

Message 3 of 22
(4,201 Views)
Is the script you're running using any global variables that have been initialized in your workspace? When you use the Matlab Script Node, it will create a new, hidden instance of Matlab (TM) that won't share any of those workspace variables (or any other data). That could account for the differences you are seeing. If this is the case, then you should prepend to your Matlab Script Node contents an initialization script that gives appropriate values to these globals before starting your simulation code.
Jarrod S.
National Instruments
Message 4 of 22
(4,200 Views)
Thanks for your interest to my problem.

There are some functions that I am using as seperate .m files and also .dat matrices. Since, definition of functions are not allowed in the script. I copied all files to the matlab\work folder. The code is working after the files were copied but giving a different result. Result is not meaningless but like some part of a function is dealt differently or missing, which changes all result. Is there another way to define functions in or to do matlab script. These functions are as the following:

function y=difsphbesselj(n,x)
y=(-1/2)*(sqrt(pi/2))*(1/x)^(3/2)*besselj(n+1/2,x)+(1/2)*(sqrt(pi/2))*(sqrt(1/x))*(besselj((-1/2)+n,x)-besselj((3/2)+n,x));

0 Kudos
Message 5 of 22
(4,162 Views)

I have similar problem. Same code, exactly the same code gives different results in matlab script of labview and on matlab alone. Also sometimes the same script works and sometimes gives error. Is there any way to make results more reliable?

0 Kudos
Message 6 of 22
(3,505 Views)

... you just added to a 5 year old thread. When you say "same code", do you mean the same code as in the 5 year old thread above or some completely unrelated code which is the same in matlab and matlab script.

 

What is your LabVIEW version? What is your matlab version? How often is "sometimes"?

 

Can you attach an example that shows the problem? DId you try some of the suggestions mentioned above?

0 Kudos
Message 7 of 22
(3,498 Views)

Labview 8.5

Matlab R2009b

Attached are the graphs produced by matlab script in labview and in matlab.

The minimum of graph produced by matlab code is below 1 and that in labview is above 1.

Thanks a lot for your reply.

Sorry, I haven't quantified the "sometimes" yet. 

 

 

Download All
0 Kudos
Message 8 of 22
(3,491 Views)

It looks to me like you have the same picture, except that the results seem to be mirrored about the line Y=X.  (the 45deg line).

 

You should check your code again and make sure it truly matches and you didn't flip your indices.

0 Kudos
Message 9 of 22
(3,474 Views)

I agree, the 2D array seems transposed, while the axis assignment (offset,increment) are not transposed. You did not show any code, but that graph is formed most lkely ouside the matlab node. We need to see some code.

0 Kudos
Message 10 of 22
(3,463 Views)