Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MATLAB中单元阵列的故障分类功能";parfor";环_Matlab_Parallel Processing_Parfor - Fatal编程技术网

MATLAB中单元阵列的故障分类功能";parfor";环

MATLAB中单元阵列的故障分类功能";parfor";环,matlab,parallel-processing,parfor,Matlab,Parallel Processing,Parfor,所以我整个上午都在做研究,不知道为什么这段代码不能运行 最初的代码是: nSim = 100; nTs = 40; nRep = 10; m1 = NaN(nTs,nSim); meanM1 = NaN(nTs,nRep); delta = [1/400,1/400,-1/400]'; d = -0.05; dataQCell = cell(nSim*nRep,1); for jj=1:nSim*nRep dataQCell{jj} = rand(3,nTs); end matlabpoo

所以我整个上午都在做研究,不知道为什么这段代码不能运行

最初的代码是:

nSim = 100;
nTs = 40;
nRep = 10;
m1 = NaN(nTs,nSim);
meanM1 = NaN(nTs,nRep);
delta = [1/400,1/400,-1/400]';
d = -0.05;
dataQCell = cell(nSim*nRep,1);
for jj=1:nSim*nRep
  dataQCell{jj} = rand(3,nTs);
end

matlabpool('open',10)
parfor ii=1:nRep
  for jj=1:nSim
    for tt=1:nTs
      if tt>1
        m1(tt,jj) = m1(tt-1,jj) + delta'* dataQCell{(ii-1)*nSim+jj,1}(1:3,tt)+d;
      else
        m1(tt,jj) = delta'* dataQCell{(ii-1)*nSim+jj,1}(1:3,tt) + d;
      end
    end
  end

  meanM1(tt,ii) = mean(m1,2);
end
matlabpool close force
我最初的想法是罪犯是

m1(tt,jj) = m1(tt-1,jj) + deltaQ'* dataQCell{(ii-1)*nSim+jj,1}(1:3,tt) + d;
由于
dataQCell
的索引是索引的函数(
ii
jj

注意,我已经注释掉了
means1
行,但仍然得到相同的错误

我的第一次尝试是通过修改代码将(
nSim*nRep
x1)单元格分解为
nRep
部分

nSim = 100;
nTs = 40;
nRep = 10;
m1 = NaN(nTs,nSim);
meanM1 = NaN(nTs,nRep);
deltaQ = [1/400,1/400,-1/400]';
d = -0.05;

dataQCell = cell(nSim*nRep,1);
for jj=1:nSim*nRep
  dataQCell{jj} = rand(3,nTs);
end

dataRepCell = cell(nRep,1);
for ii=1:nRep
  dataRepCell{ii} = dataQCell{(ii-1)*nSim+1:ii*nSim};
end

matlabpool('open',10)
parfor ii=1:nRep
  for jj=1:nSim
    for tt=1:nTs
      if tt>1
        m1(tt,jj) = m1(tt-1,jj) + deltaQ'* dataRepCell{ii}{jj}(1:3,tt)+d;
      else
        m1(tt,jj) = deltaQ'* dataRepCell{ii}{jj}(1:3,tt) + d;
      end
    end
  end

  meanM1(tt,ii) = mean(m1,2);
end
matlabpool close force

但是我得到了相同的“无法分类变量‘m1’”,错误。

问题是,
m1
不允许被分类为临时变量,因为我在
parfor
循环之前预先分配了矩阵。解决方案是在
parfor
循环内运行
m1=Nan(nTs,nSim)

请尝试将您的代码转换为:删除所有不必要的代码并提供所有输入,以便我们可以自己运行您的代码并重现错误。代码现在应该可以执行了。唯一的问题是我相信matlabpool并没有在最新版本的MATLAB中使用