matrix dimension error for interpolation in loop
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Matt J
il 14 Dic 2012
Modificato: Matt J
il 14 Dic 2012
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.
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!