How do I save data created inside a parfor inside an app?
이전 댓글 표시
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
Mario Malic
2021년 2월 12일
Hello,
you can't save an app object, but you can get assign value from its properties to a variable and save it.
Jonathan Wharrier
2021년 2월 12일
Mario Malic
2021년 2월 12일
편집: Mario Malic
2021년 2월 12일
In general, you can't save app. Let's move on from there.
othersave(app,g); % I don't know what this is
In the post, the code was set up as a function, so that after it ends, it outputs the result. You can do the same. In the callback call the function and save the result.
Jonathan Wharrier
2021년 2월 13일
Walter Roberson
2021년 2월 13일
External function in its own .m file instead of static class function.
Jonathan Wharrier
2021년 2월 13일
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Parallel for-Loops (parfor)에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!