How do I save data created inside a parfor inside an app?
1 view (last 30 days)
Show older comments
I have an app which ises a parfor to do major calculation the result of which is a large matrix for each parfor loop that I wish to save.
essentially I have
function ContinueButtonPushed(app, event)
app.TabGroup.SelectedTab = app.SetUpTab;
%app.RUNButton.Enable = 0;
app.comment.Value = 'Running...';
% lots of set up stuff here
parfor loop = startloop:endloop
%************************************
%create a name for the save file
%************************************
fl = join([f num2str(loop) '.mat']);
...
U = zeros(M+2,NJl); %output file
...
for j=1:NJl %produces an array 1000x1000 and bigger
U1=AA\(1i.*U0l - AB*U0l - sp*dtl*(U0l.*conj(U0l)).*U0l - B(:,j)-B(:,j+1));
UC = (U1+U0l)/2;
U1=AA\(1i.*U0l - AB*U0l - sp*dtl*(UC.*conj(UC)).*UC...
- B(:,j)-B(:,j+1))- deltaNoise(j);
U0l=U1; U(:,j) = [Ul(j+1);U1;Ur(j+1)];
end
parsave(fl,U0l); %cannot use save within a parfor
end
%**********************************************************************
% create a name and then save the parameters for later (P_X) file
%**********************************************************************
g = join(['U_L' num2str(app.xmax) 'run' num2str(app.runnumber) 'P_X.mat']);
app.loopmax = app.loopmax+app.offset;
othersave(app,g);
delete(gcp('nocreate'));
end
If I use parsave like this I get an error that I need to use
parsave(app,fl,U0l);
However this gives an error because the app value cannot be used in the parfor loop. One suggestion was to use a static function
methods (Access = private, Static)
function parsave(fname, vr)
save(fname, 'vr', '-v7.3')
end
end
Still doesn't work. I really need to save this data. If it is not in the app then the save works fine...
Answers (0)
See Also
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!