[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Octave: invalid use of script in index expression
From: |
afullo |
Subject: |
Octave: invalid use of script in index expression |
Date: |
Wed, 20 Mar 2013 08:21:40 -0700 (PDT) |
I've got some script, but one of them doesn't work properly. Specifically,
HaltonProva gives:
/error: invalid use of script in index expression
error: called from:
error: /home/fabio/Matematica/Meshfree/HaltonProva.m at line 19, column 4/
where the script and its calls follow (they are in distinct .m files, just
listed consecutively here):
/%%% HaltonProva.m
% bidimensionale
% x = HaltonSequence(100,2);
% y = HaltonSequence(100,3);
% plot(x,y,'.o')
% axis([0 1 0 1])
% axis square
% tridimensionale
% x = HaltonSequence(500,2);
% y = HaltonSequence(500,3);
% z = HaltonSequence(500,5);
% plot3(x,y,z,'.o')
% axis square
% grid on
% prova con la fill distance
xh = HaltonSequence(25,2);
yh = HaltonSequence(25,3);
hh = FillDistance(xh,yh)
xr = rand(25,1);
yr = rand(25,1);
hr = FillDistance(xr,yr)
%%% HaltonSequence.m
function hs = HaltonSequence(n,b)
hs = zeros(n,1);
for idx = 1:n
hs(idx) = localHaltonSingleNumber(idx,b);
end
%%% FillDistance.m
hX = FillDistance(x,y)
neval = 40;
grid=linspace(0,1,neval);
[xe,ye]=meshgrid(grid);
epoints=[xe(:) ye(:)];
ctrs=[x y];
DM_eval=DistanceMatrix(epoints,ctrs);
hX=max(min(DM_eval'));
%%% localHaltonSingleNumber.m
function hn = localHaltonSingleNumber(n,b)
n0 = n;
hn = 0;
f = 1/b;
while(n0>0)
n1 = floor(n0/b);
r = n0-n1*b;
hn = hn + f*r;
f = f/b;
n0 = n1;
end
%%% DistanceMatrix.m
% DM = DistanceMatrix(dsites,ctrs)
% Forms the distance matrix of two sets of points in R^s,
% i.e., DM(i,j) = || datasite_i - center_j ||_2.
% Input
% dsites: Mxs matrix representing a set of M data sites in R^s
% (i.e., each row contains one s-dimensional point)
% ctrs: Nxs matrix representing a set of N centers in R^s
% (one center per row)
% Output
% DM: MxN matrix whose i,j position contains the Euclidean
% distance between the i-th data site and j-th center
function DM = DistanceMatrix(dsites,ctrs)
[M,s] = size(dsites); [N,s] = size(ctrs);
DM = zeros(M,N);
% Accumulate sum of squares of coordinate differences
% The ndgrid command produces two MxN matrices:
% dr, consisting of N identical columns (each containing
% the d-th coordinate of the M data sites)
% cc, consisting of M identical rows (each containing
% the d-th coordinate of the N centers)
for d=1:s
[dr,cc] = ndgrid(dsites(:,d),ctrs(:,d));
DM = DM + (dr-cc).^2;
end
DM = sqrt(DM);/
How can I fix it?
Thanks in advance. :)
--
View this message in context:
http://octave.1599824.n4.nabble.com/Octave-invalid-use-of-script-in-index-expression-tp4651057.html
Sent from the Octave - General mailing list archive at Nabble.com.
- Octave: invalid use of script in index expression,
afullo <=