matlab函数文件,调用时等号左边调用返回值,为什么会报错?

  1. 云栖社区>
  2. 博客>
  3. 正文

matlab函数文件,调用时等号左边调用返回值,为什么会报错?

游客z2wb6rzfc2qyg 2019-08-25 12:41:42 浏览176
展开阅读全文

3a8479a4d185a03e2fe4a6868e30899
0757412a43a12f8738d846b7f696fca
以下是.m代码,明明代码中给出返回值了,为什么会报错,我真的是快疯了!!求大神指点迷津~

function [mse,bestc,bestg] = SVMcgForRegress(train_label,train,cmin,cmax,gmin,gmax,v,cstep,gstep,msestep)

%SVMcg cross validation by faruto
%Email:farutoliyang@gmail.com QQ:516667408 http://blog.sina.com.cn/faruto BNU
%last modified 2009.8.23
%Super Moderator @ www.ilovematlab.cn
%% about the parameters of SVMcg

if nargin < 10

msestep = 0.06;

end
if nargin < 7

v = 3;
cstep = 1;
gstep = 1;

end
if nargin < 6

v = 3;
cstep = 1;
gstep = 1;
gmax = 5;

end
if nargin < 5

v = 3;
cstep = 1;
gstep = 1;
gmax = 5;
gmin = -5;

end
if nargin < 4

v = 3;
cstep = 1;
gstep = 1;
gmax = 5;
gmin = -5;
cmax = 5;

end
if nargin < 3

v = 3;
cstep = 1;
gstep = 1;
gmax = 5;
gmin = -5;
cmax = 5;
cmin = -5;

end
%% X:c Y:g cg:acc
[X,Y] = meshgrid(cmin:cstep:cmax,gmin:gstep:gmax);
[m,n] = size(X);
cg = zeros(m,n);
%% record acc with different c & g,and find the bestacc with the smallest c
bestc = 0;
bestg = 0;
mse = 10^10;
basenum = 2;
for i = 1:m

for j = 1:n
    cmd = ['-v ',num2str(v),' -c ',num2str( basenum^X(i,j) ),' -g ',num2str( basenum^Y(i,j) ),' -s 3 -p 0.1 -n 0.1'];
    cg(i,j) = libsvmtrain1(train_label, train, cmd);
    
    if cg(i,j) < mse
        mse = cg(i,j);
        bestc = basenum^X(i,j);
        bestg = basenum^Y(i,j);
    end
    if ( cg(i,j) == mse && bestc > basenum^X(i,j) )
        mse = cg(i,j);
        bestc = basenum^X(i,j);
        bestg = basenum^Y(i,j);
    end
    
end

end
%% to draw the acc with different c & g
[cg,ps] = mapminmax(cg,0,1);
figure;
[C,h] = contour(X,Y,cg,0:msestep:0.5);
clabel(C,h,'FontSize',10,'Color','r');
xlabel('log2c','FontSize',12);
ylabel('log2g','FontSize',12);
title('参数选择结果图(等高线图)','FontSize',12);
grid on;

figure;
meshc(X,Y,cg);
% mesh(X,Y,cg);
% surf(X,Y,cg);
axis([cmin,cmax,gmin,gmax,0,1]);
xlabel('log2c','FontSize',12);
ylabel('log2g','FontSize',12);
zlabel('MSE','FontSize',12);
title('参数选择结果图(3D视图)','FontSize',12);

网友评论

登录后评论
0/500
评论
游客z2wb6rzfc2qyg
+ 关注