使用Matlab进行parfor“在parfor中的变量__无法分类". [英] parfor with Matlab "the variable __ in a parfor cannot be classified"

查看:3865
本文介绍了使用Matlab进行parfor“在parfor中的变量__无法分类".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我尝试使用parfor调用此函数(基本上是通过parfor循环中的向量使用傅立叶级数进行曲线拟合):

So I am trying to call this function using a parfor (basically curve fitting using Fourier series through a vector in a parfor loop):

function[coefnames,coef] = fourier_regression(vect_waves,n)

    coef = zeros(length(vect_waves)-n,18);
    current_coef = zeros(18,1); % All the terms of the fourier series
    x = 1:n;

    parpool_obj = parpool;
    parfor i=n:length(vect_waves)

        take_fourier = vect_waves(i-n+1:i);

        f = fit(x,take_fourier,'fourier8');
        current_coef = coeffvalues(f);
        coef(i,1:length(current_coef)) = current_coef;

    end
    coefnames = coeffnames(f);

    delete(parpool_obj);
end

但是我刚得到错误

"parfor中的变量coef无法分类. 请参见MATLAB中的Parallel for Loops,概述".

"The variable coef in a parfor cannot be classified. See Parallel for Loops in MATLAB, "Overview".

我似乎无法在任何地方找到解决方案,我也不知道问题出在哪里.发生了什么事?

I can't seem to find the solution anywhere, I don't know what the problem is. What's going on?

推荐答案

@Andras Deak在注释中添加了此内容,但此方法确实很简单-您需要做的只是对第二个下标使用一种索引形式parfor允许的coef.在这种情况下,您需要执行以下操作:

@Andras Deak put this in a comment, but the fix here is really simple - all you need to do is use a form of indexing for the second subscript to coef that is allowed by parfor. In this case, you need to do:

parfor i = ...
    coef(i, :) = ...;
end

这篇关于使用Matlab进行parfor“在parfor中的变量__无法分类".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆