Transparency violation error. 'save' in 'parfor' loop

조회 수: 3 (최근 30일)
Giridhar sai pavan kumar Konduru
답변: Mohammad Sami 2021년 5월 12일
I am new to coding,
Here's the complete code:
Dset = 'visit3'; % visit3
Mpath = 'E:\OneDrive - IITRAM'; %dataset path
Lpath = 'E:\datasetttt\numom2b\polysomnography';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
sp1 = 'MAT files';
op1 = 'edfs'; %edfs
op2 = 'annotations-events-profusion'; %xml
Ldir = struct2cell(dir([Lpath,'\',op1,'\',Dset]));
Ldir = Ldir(1,3:end)';
sp2 = strcat(Mpath,'\',sp1,'\',Dset);
if isfolder(sp2) ==0
mkdir(sp2)
end
parfor i = 1:1903 %size(Ldir,1)
CSname = char(Ldir(i,1));
[hdr, record] = edfread(CSname); % Edf2mat
CSname = CSname(1:end-4);
y = xml2struct([CSname,'-profusion.xml'],0);
save([sp2,'\',CSname,'_rec'],'record')
save([sp2,'\',CSname,'_info'],'hdr','y')
clc
disp(i)
toc
end
I know this error comes cuz of the 'save' in 'parfor' loop
people have suggested that we have to define the save as a function
But i am having a hard time figuring it out
I'd be glad if someone helps
thank you.

채택된 답변

Mohammad Sami
Mohammad Sami 2021년 5월 12일
How about you define two save functions
function mysave1(sp2,CSname,record)
save([sp2,'\',CSname,'_rec'],'record');
end
function mysave2(sp2,CSname,hdr,y)
save([sp2,'\',CSname,'_info'],'hdr','y')
end
Then just call these in your parfor loop.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by