Problem with parfor loop (not enough input arguments)

조회 수: 8 (최근 30일)
Swapnil Sayan Saha
Swapnil Sayan Saha 2019년 5월 25일
댓글: Swapnil Sayan Saha 2019년 6월 5일
I'm having problem with the following snippet of code:
parfor i = 1:196072
z = x(i,:);
z1 = filter(Hd, z);
fprintf(fid, '%20.6f', z1);
fprintf(fid, '\n');
end
fclose(fid);
As soon as I run the code snippet, it says: Not Enough Input Arguments.
However, the code works fine using normal for loop. I tried shutting down and restarting Parpool but no effect. I also tried restarting MATLAB, no effect. I tried deleting local_cluster_jobs folder in C:/Users/AppData/Roaming/MATLAB but no effect.
  댓글 수: 3
Walter Roberson
Walter Roberson 2019년 5월 26일
Is Hd possibly a global variable?
Swapnil Sayan Saha
Swapnil Sayan Saha 2019년 5월 26일
I solved it.
The filter function can work in two ways:
First method: filter function works with a filter object: filter(Hd, x), where Hd is a filter object exported from FilterDesigner... second method: filter function works with filter coefficients: filter(b,a,x), where b and a are filter transfer function coefficients.. x is the signal..
For some reason, parfor loop cannot process Hd.. So i just exported the coefficents in the workspace and used them inside the loop, also made a couple of changes to better optimize memory usage.
fid = fopen('bagaccx_f.txt','w');
fclose(fid);
parfor i = 1:196072
fid = fopen('bagaccx_f.txt','a');
fprintf(fid, '%f\t', filter(b,a, x(i,:)));
fprintf(fid, '\n');
fclose(fid);
end

댓글을 달려면 로그인하십시오.

채택된 답변

Swapnil Sayan Saha
Swapnil Sayan Saha 2019년 5월 26일
I solved it.
The filter function can work in two ways:
First method: filter function works with a filter object: filter(Hd, x), where Hd is a filter object exported from FilterDesigner... second method: filter function works with filter coefficients: filter(b,a,x), where b and a are filter transfer function coefficients.. x is the signal..
For some reason, parfor loop cannot process Hd.. So i just exported the coefficents in the workspace and used them inside the loop, also made a couple of changes to better optimize memory usage.
fid = fopen('bagaccx_f.txt','w');
fclose(fid);
parfor i = 1:196072
fid = fopen('bagaccx_f.txt','a');
fprintf(fid, '%f\t', filter(b,a, x(i,:)));
fprintf(fid, '\n');
fclose(fid);
end
  댓글 수: 2
Walter Roberson
Walter Roberson 2019년 5월 26일
Was Hd a global variable? If so then parfor would have seen it as [] in the workers, as the content of global variables is not copied to workers.
Swapnil Sayan Saha
Swapnil Sayan Saha 2019년 6월 5일
Yes. Maybe that was a problem.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Identification에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by