Use parfor and getting "Index exceeds matrix dimensions" error

1 回表示 (過去 30 日間)
NOOR AL-SHAKARJI
NOOR AL-SHAKARJI 2017 年 2 月 25 日
コメント済み: NOOR AL-SHAKARJI 2017 年 2 月 26 日
Pleas need help , I use Parfor to run the code in parallel but I got "Index exceeds matrix diamensions"
when I run the code with for it runs normally.
Rootpath=('............');
flist1=dir(fullfile(Rootpath));
parfor i=3: size (flist1,1)
inputpath=strcat(Rootpath,'/',flist1(i).name,'/');
outpath=strcat('./Output/',flist1(i).name,'/');
if ~isdir(outpath)
mkdir(outpath);
end
Read_main(inputpath,outpath)
end
  2 件のコメント
Walter Roberson
Walter Roberson 2017 年 2 月 25 日
Which line is the error report on?
I recommend by the way that you use fullfile to create the path names
NOOR AL-SHAKARJI
NOOR AL-SHAKARJI 2017 年 2 月 26 日
on parfor line

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2017 年 2 月 26 日
You could end up with mysterious path problems in the case that your Rootpath was a global variable. Global variables are not copied to parfor workers.
  3 件のコメント
Walter Roberson
Walter Roberson 2017 年 2 月 26 日
If it is a global variable, copy it to a local variable and use that in the code.
Alternately, you can use parfevalOnAll() before running the parfor, running a small bit of code that creates Rootpath as a global variable and initializing it with the appropriate value.
Or since you do not appear to write to the variable in the code, you could use parallel.pool.constant()
But really, for a simple variable such as this, best would just be to avoid using a global variable.
NOOR AL-SHAKARJI
NOOR AL-SHAKARJI 2017 年 2 月 26 日
Thank You Alot!!!
Now it works
I just put the globla variable inside the body of parfor

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeParallel for-Loops (parfor) についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by