Matlab code error - matlab code error - Subscript indices must either be real positive integers or logicals

1 次查看(过去 30 天)
I am getting an error in a matlab code...
Here is my matlab code....
a = 0;
b = 1000;
ftype ='function estimation';
y1 = [];
y2 = [];
y3 = [];
y6 = [];
p=a+(b-a)*lhsdesign(100,2);
s = length(p(:,1));
ydata = -log(ydata);
ytest = -log(ytest);
for k = 1:10
for n = 1:s
gam = p(n,1);
sig2 = p(n,2);
[alpha1,b1] = trainlssvm({xdata,ydata,ftype,gam,sig2,'RBF_kernel'});
tic
ysvm = simlssvm({xdata,ydata,ftype,gam,sig2,'RBF_kernel','preprocess'},{alpha1,b1},xtest);
toc
y4 = toc;
A = ysvm-ytest;
y5 = (sum(A.*A))/5000;
*y6 = corr(ytest,ysvm);*
y4 = [y1; y4];
y5 = [y2; y5];
y6 = [y3; y6];
y1 = y4;
y2 = y5;
y3 = y6;
end
gam = p(:,1);
sig2 = p(:,2);
time = y4;
mse = y5;
corr = y6;
xyz = [gam sig2 time mse corr];
xyz = sortrows(xyz,4);
xyz = xyz(1,:);
gam = xyz(1,1);
sig2 = xyz(1,2);
time = xyz(1,3);
mse = xyz(1,4);
corr = xyz(1,5);
if (mse <= 0.00001)
exit;
else
mse = mse;
end
if (gam <= 0)
gam = 1000;
else
gam = gam;
end
mu = [gam sig2];
SIGMA = [0.1 0; 0 0.1];
p = mvnrnd(mu,SIGMA,100);
s = length(p(:,1));
y1 = [];
y2 = [];
y3 = [];
end
I am getting the error in line
y6 = corr(ytest,ysvm)
Please help...

采纳的回答

Mickaël Tits
Mickaël Tits 2014-6-13
Actually the problem is simply that you used "corr" as the name of a variable, so when you type
y6 = corr(ytest,ysvm)
you don't really call the function, but look in your variable corr at indices ytest and ysvm (that a probably not integers, so the error).

更多回答(1 个)

Walter Roberson
Walter Roberson 2013-1-16
Please use
which corr
to verify that there is a corr() routine. corr() is part of the Statistics Toolbox, not part of basic MATLAB.

类别

Help CenterFile Exchange 中查找有关 Psychology 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by