matrix dimension error for interpolation in loop

조회 수: 1 (최근 30일)
Melissa
Melissa 2012년 12월 14일
Good Afternoon All,
I seem to be having a bit of trouble with matrix dimensions agreeing (I know rookie mistake). I am using radial basis functions and have created a model which I want to evaluate. I seem to be having the error here:
for j = 1:nSites
r(j) = norm(x - rbfmodel.X(j,:)');
end
Error in evalRBF (line 21)
r(j) = norm(x - rbfmodel.X(j,:)');
where Nsites is the number of sites in the original data points (rbfmodel.X) and x is the vector of points to be evaluated.
I think that I need some sort of indexing for x, maybe something along the lines of:
r = zeros(nSites,nSites);
for i = 1:nSites
for j = 1:i-1
r(i,j) = norm(x(i,:) - rbfmodel.X(j,:));
end
r(1:i-1,i) = r(i,1:i-1);
end
Anyone have suggestions?
Here is the code for evalRBF
function fx = evalRBF(x,rbfmodel)
% EVALRBF(X,RBFMODEL)Evaluates a radial basis function surrogate at a given point
% Input:
% x = the point to be evaluated
% rbfmodel = structure of all parameters that define the RBF surrogate
% .X = matrix of data sites
% .kernel = string indicating the choice of kernel function
% .coeff = coefficients that define the RBF
% Output:
% fx = RBF value at x
% nSites is the number of data sites provided in Original Model
[nSites] = size(rbfmodel.X,1);
% r is the vector of distances between data sites
r = zeros(nSites,1);
for j = 1:nSites
r(j) = norm(x - rbfmodel.X(j,:)');
end
% Adjust x as necessary
if strcmp(rbfmodel.poly,'regpoly0')
x = [];
else
x = feval(typePoly,x');
x = x';
x(1,:) = [];
end
% Evaluate RBF at x
y = [kernelRBF(rbfmodel.kernel,r,rbfmodel.c); 1; x(:)];
fx = rbfmodel.coeff'*y;
if ~isfinite(fx)
fx = 1/eps;
end
return
  댓글 수: 3
Melissa
Melissa 2012년 12월 14일
it is someone elses, yes. I size(x) depends on what data I wanted evaluated and rbfmodel.X will return original size matrix (ie for my exaple is 2x79). is there a way to get it for work say I want to evaluate x and its only at one point [50,50].
Matt J
Matt J 2012년 12월 14일
편집: Matt J 2012년 12월 14일
Well first of all, it should be clear to you now where your bug is coming from. If x is always a 1x2 row vector (as with [50,50]) you will clearly not be able to subtract it from a 1x79 row vector (as rbfmodel.X(j,:) will be).
If you really want x to be a 2x1 column vector and you want it to be subtracted from every column of rbfmodel.X, change the relevant line as in my Answer below.

댓글을 달려면 로그인하십시오.

답변 (1개)

Matt J
Matt J 2012년 12월 14일
편집: Matt J 2012년 12월 14일
A first guess
r(j) = norm(x(:) - rbfmodel.X(:,j));

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by