11-01-2011 08:48 AM
Dear LabVIEW team,
I tried to run the example given on the lsqfit page:
http://zone.ni.com/reference/en-XX/help/371361G-01/lvtextmath/msfunc_lsqfit/
I made a file called myfit.m which contains:
% The myfun function is defined by:
function [F, df] = myfun(a, xdata)
F = a(1)*xdata.^2 + a(2)*cos(xdata);
df = zeros(0, 0);
and a script named testfit.m (both in the same folder):
a = [2, 1.5];
x = 0:1:19;
noise = randnormal(size(x)) / 5;
y = a(1)*x.^2 + a(2)*cos(x) + noise;
[x, normres, resid] = lsqfit('myfun', [10, 10], x, y);
Then the output in MathScript is:
>>
Error in function lsqfit at line 5: The function you specified as an argument is invalid.
Line 5: [x, normres, resid] = lsqfit('myfun', [10, 10], x, y);
I am not familiar with mathscript / matlab (yet) so I don't see what is going wrong here. But as this is an example taken from your homepage I assume it should work.
Thanks,
Philipp Oertle
11-01-2011 11:13 AM
Hi Philipp,
Try renaming your "myfit.m" file to "myfun.m". The compiler is expecting the function to be defined in a similarly named file.
Cheers!
K Scott
11-01-2011 12:23 PM
Oops, that was a tipo in the post! Sorry for that. The file is already named 'myfun.m'
Philipp
11-01-2011 05:00 PM
Hmmm. I was sure that was the issue. Could you try to simplify it a little? For instance, placing the testfit.m contents into the MathScript Node directly and running the VI?
Additionally, what versions of LabVIEW/MathScript are you using and on what operating system?
Thanks,
-K Scott