How do I save data created inside a parfor inside an app?
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...
6 Comments
Mario Malic
on 12 Feb 2021
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
on 12 Feb 2021
Mario Malic
on 12 Feb 2021
Edited: Mario Malic
on 12 Feb 2021
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
on 13 Feb 2021
Walter Roberson
on 13 Feb 2021
External function in its own .m file instead of static class function.
Jonathan Wharrier
on 13 Feb 2021
Answers (0)
Categories
Find more on Loops and Conditional Statements 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!