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

3 次查看(过去 30 天)
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