How do I save data created inside a parfor inside an app?

조회 수: 2 (최근 30일)
Jonathan Wharrier
Jonathan Wharrier 2021년 2월 12일
댓글: Jonathan Wharrier 2021년 2월 13일
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...
  댓글 수: 6
Walter Roberson
Walter Roberson 2021년 2월 13일
External function in its own .m file instead of static class function.
Jonathan Wharrier
Jonathan Wharrier 2021년 2월 13일
I think you could be right. Rather defeats the object in terms of packaging but I haven't come up with anmything better. I will give it a go and see what turns up! Tx

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by