function [bestacc,bestc] = SVMcgForClass_NoDisplay_linear(train_label,train,cmin,cmax,v,cstep)
% modified from libsvm
%%the parameters of SVMcg
if nargin < 6
    cstep = 0.8;
end
if nargin < 5
    v = 5;
end
if nargin < 3
    cmax = 8;
    cmin = -8;
end
%% X:c Y:g cg:CVaccuracy
X = meshgrid(cmin:cstep:cmax,1);
[m,n] = size(X);
cg = zeros(v,n);
eps = 1e-1;
%% record acc with different c & g,and find the bestacc with the smallest c
bestc = 1;
bestacc = 0;
basenum = 2;
bestc_nc =[]
%%if the train label named by label

label_for_nCV = train_label
train_for_nCV = train
CrossValIndices = crossvalind('Kfold', label_for_nCV,v)



for j = 1:n
    
%%%here need to add a k fold to choose the train_data and train_label
    for k=1:v
        train_label = label_for_nCV(CrossValIndices~=k,:);
        train = train_for_nCV(CrossValIndices~=k,:);
        test_label = label_for_nCV(CrossValIndices==k,:);
        test = train_for_nCV(CrossValIndices==k,:);
    %    cmd = ['-v ',num2str(v),' -c ',num2str( basenum^X(i,j) )];
    %%get rid of the cross-validation, so we need to add k-fold outside
        cmd = ['-c ',num2str( basenum^X(1,j) )]
        %cg(i,j) = svmtrain(train_label, train, cmd);
        model = svmtrain(train_label, train, cmd);
        [predicted_label, accuracy, deci] = svmpredict(test_label,test,model);
        cg(k,j) = accuracy(1);
        end
    if mean(cg(:,j)) <= 55
        continue;
    end

    if mean(cg(:,j)) > bestacc
        bestacc = mean(cg(:,j));
        bestc = basenum^X(1,j);
    end

    if abs( mean(cg(:,j))-bestacc )<=eps && bestc > basenum^X(1,j)
        bestacc = mean(cg(:,j));
        bestc = basenum^X(1,j);
    end
end

