Scripting for LME

39 views
Skip to first unread message

arroxelas

unread,
May 21, 2009, 1:15:46 PM5/21/09
to Sysquake
Hi,

I'm looking for a way to do some scripting for LME, just like you can
script stuff on matlab using .m files. I was able to make scripts for
LME using .lml.txt files on the /lib/ directory but I had to put a
"define" in front of every variable I defined. Is there a way to do
scripting just as in matlab? If not, what's the easiest way?

Thanks in advance.

Yves Piguet

unread,
May 21, 2009, 4:21:52 PM5/21/09
to sysq...@googlegroups.com


There aren't scripts like in Matlab. All the code should be written
as functions. If you write "function fun" before your code, you can
execute it by typing "fun", assuming you've loaded the library with
"use filename" where filename is the library filename without any
suffix. The main difference with scripts is that variables defined
in functions are local. You can have multiple functions per library.

Hope this helps,

Yves

arroxelas

unread,
May 21, 2009, 6:20:42 PM5/21/09
to Sysquake
Helped a lot! Thanks!

Chuck

unread,
Jun 6, 2009, 4:23:21 PM6/6/09
to Sysquake
Here's an example of a Sysquake file "linfit.lml" (similar to Matlab's
m-file) I used for doing a linear fit to x-y data.

% linfit(x,y,flag) returns the coefficient vector of a linear fit
% to data points specified by column vectors x and y and the
% correlation coefficient of the fit. If flag is true, a plot
% of the data points and the least-squares line are generated
% with error bars from the data points to the line. If optional
% parameter flag is false (the default), no plot is generated.
function (coef,r) = linfit(x,y,flag)
if (nargin < 3)
flag=false;
end
a=[x x.^0];
b=y;
% find coefficients (c(1)*x + c(2))
ata=a'*a;
coef=ata^-1*(a'*b);
n=length(x);
% calculate the correlation coefficient
r=coef(1)*sqrt(det(ata))/sqrt(n*y'*y-(sum(y))^2);
yfit=polyval(coef,x);
% calculate the root-mean-square error
%error=y-yfit;
%rms_error=sqrt(mean(error.^2));
fprintf('y = %f x + %f\n',coef(1),coef(2))
fprintf('r = %f\n', r)
if flag
% plot data points
clf
plot(x,y,'bo')
label('x','y')
title('y as a function of x')
% plot least-squares line in 100 steps
xp=[x(1):(x(n)-x(1))/(100-1):x(n)];
yp=polyval(coef,xp);
plot(xp,yp)
% plot error bars from data points to line
for k=1:n
d=[x(k) x(k)];
e=[y(k) yfit(k)];
plot(d,e,'r-')
end
end
Reply all
Reply to author
Forward
0 new messages