如何在matlab中将单元变量转换为parfor循环内的分类变量?

时间:2016-05-16 17:52:09

标签: matlab

我在matlab中使用parfor循环,但我遇到了一个案例,我不知道如何解决它。 我想在名为 err_list 的列表中保存计算错误,但是Matlab给了我一个错误。有人可以帮我解决这个问题吗? 这是我的代码,everyrthing工作正常,但错误在代码的最后四行有所影响,并告诉我, err_list 未被分类。

err_list = cell(length(lambda1_list),2);

 parfor l1 = 1:length(lambda1_list) % over l1
            this_param = params;


        % Create this to save CV error:
        tmp=zeros(params.nfolds,1);

    for l2 = 1:length(lambda2_list)



        this_param.lambda1 = lambda1_list(l1);
        this_param.lambda2 = lambda2_list(l2);
        % Get Nth fold training and test data and compute CV error
        for Fold=1:size(Fold_indices,2)

        Y_train=y_train(logical(Fold_indices(:,Fold)),1:end);
        Y_test=y_train(~logical(Fold_indices(:,Fold)),1:end);

        N=size(Y_test,1);
        Dictionary_train=dictionary_train(logical(Fold_indices(:,Fold)),1:end);

       Dictionary_test=dictionary_train(~logical(Fold_indices(:,Fold)),1:end);


        [totBeta,theta,omega,rho,nu] = learn(Dictionary_train,Y_train, this_param);


       err = (1/N) * sum(sum(( Y_test- Dictionary_test * totBeta).^2));

       %err
       tmp(Fold,1)=err;
        totBeta




    end
       err_list{l1,1}=mean(tmp);
       err_list{l1,2}=[lambda1_list(l1),lambda2_list(l2)];
    % for loop  l2
end %

以下是我收到的错误:

Error: File: holdOutMethod.m Line: 111 Column: 8
The variable err_list in a parfor cannot be classified.
See Parallel for Loops in MATLAB, "Overview".

0 个答案:

没有答案