parfor loop error with plotting on an image

Hello, I have an image that I want to perform some analysis in regions using the parallel toolbox. To begin with I just want to visualise each region to ensure its correct first and have done this basic parfor loop
parfor i=1:10
plot(ax,xl+250,i*250,'c.','Markersize',20);
% later do some analysis
end
But Im getting this error:
Warning: Unable to save App Designer app object. Save not supported for matlab.apps.AppBase objects.
Warning: Unable to save App Designer app object. Save not supported for matlab.apps.AppBase objects.
Warning: While loading an object of class 'HTS_TestSoftware':
Unable to load App Designer app object. Load not supported for matlab.apps.AppBase objects.
> In matlab.ui.control.UIAxes.convertAxes
In matlab.ui.control/UIAxes/convertToAxes
In matlab.ui.control/UIAxes/get.Axes
In parallel.internal.pool.optionallySerialize (line 10)
In parallel.internal.parfor/ParforEngine/buildParforController (line 111)
In parallel.internal.parfor/ParforEngine (line 81)
In parallel.parfor/PoolOptions/createEngine (line 32)
In parallel_function>@(initData,F)createEngine(M,initData,F,N) (line 442)
In parallel_function (line 459)
In HTS_TestSoftware/testButtonPushed (line 26748)
In matlab.apps.AppBase>@(source,event)executeCallback(ams,app,callback,requiresEventData,event) (line 60)
Warning: Unable to save App Designer app object. Save not supported for matlab.apps.AppBase objects.
Warning: Unable to save App Designer app object. Save not supported for matlab.apps.AppBase objects.
Warning: Unable to save App Designer app object. Save not supported for matlab.apps.AppBase objects.
Warning: Unable to save App Designer app object. Save not supported for matlab.apps.AppBase objects.
Warning: While loading an object of class 'HTS_TestSoftware':
Unable to load App Designer app object. Load not supported for matlab.apps.AppBase objects.
> In matlab.ui.control.UIAxes.convertAxes
In matlab.ui.control/UIAxes/convertToAxes
In matlab.ui.control/UIAxes/get.Axes
In parallel.internal.pool.optionallySerialize (line 10)
In parallel.internal.parfor/ParforEngine/buildParforController (line 111)
In parallel.internal.parfor/ParforEngine (line 81)
In parallel.parfor/PoolOptions/createEngine (line 32)
In parallel_function>@(initData,F)createEngine(M,initData,F,N) (line 442)
In parallel_function (line 459)
In HTS_TestSoftware/testButtonPushed (line 26748)
In matlab.apps.AppBase>@(source,event)executeCallback(ams,app,callback,requiresEventData,event) (line 60)
Warning: Unable to save App Designer app object. Save not supported for matlab.apps.AppBase objects.
Warning: Unable to save App Designer app object. Save not supported for matlab.apps.AppBase objects.
Any suggestions please.

 Accepted Answer

The code you are attempting to run in parallel makes some reference to the app object or some substructure of the app object.
In order for that code to be executed in parallel, the app object would have to be copied into the workers. The method of transferring objects to the workers is to save the objects to a binary representation, and then restore the binary representation on the workers -- which would create multiple copies of the app object if the procedure worked.
However, app objects cannot be saved to binary representation. They are protected so that there is only ever one single copy, which cannot be recreated on workers.
If your workers need to alter the properties of the app object in any way, then you are out of luck.
If you workers only need to examine properties of the app object, then the work-around is to copy those properties into individual local variables, and reference the local variables in the parallel region.
You appear to be attempting to plot to a shared axes within a parallel region. That is completely disallowed. Even if the axes object were to be copied into the worker, because of the save / restore process, the copied axes would refer to a per-worker local axes.
What is possible is to copy the axes into the worker, plot into the copy in the worker, and then export the revised axes back to the client, with the client being responsible for reconciling the various axes objects. However, be advised that most of the time, it is more efficient for the worker to prepare the data for plotting, and export the data back to the client, with the client being responsible for the final plotting.
N = 10;
saved_x = cell(N,1);
saved_y = cell(N,1);
parfor i=1:N
saved_x{i} = xl+250;
saved_y{i} = i*250;
end
for i = 1 : N
plot(ax, saved_x{i}, saved_y{i}, 'c.','Markersize',20);
hold(ax, 'on');
end

6 Comments

Jason
Jason on 7 Feb 2026 at 8:04
Edited: Jason on 7 Feb 2026 at 8:12
Thanks Walter, if Im actually doing the plotting in normal for loop, then I may aswell just use that rather than the parfor loop.
Can I ask, if I want to put a function inside the parfor loop that is one of my public functions, hence is typically
function(app,x,y,z)
I've noticed the parfor loop runs, but I get this warning
In parallel.internal.pool.optionallyDeserialize (line 7)
Warning: While loading an object of class 'HTS_TestSoftware':
Unable to load App Designer app object. Load not supported for matlab.apps.AppBase objects.
How do I handle this?
For example you can do
function Whatever(app_ax, app_signal, app_Fs, x, y, z)
called via
Whatever(app.ax, app.signal, app.Fs, x, y, z)
where you copy in the individual properties that you need, instead of all of app.
Note that it is possible to copy in an axes object, resulting in a local copy of the app object. Modifying it by using set() or setting ax properties or by using something like plot(ax,...) will result in the local version being affected, with the changes not being reflected back to the original version.
Jason
Jason on 7 Feb 2026 at 14:30
Edited: Jason on 7 Feb 2026 at 14:59
Thanks Walter. Now you've totally confused me (sorry)
So I assumed you always needed the 'app' argument in a function to enable it to be called anywhere within the app rather than passing in a certain app object. For example, I have a pushbutton that in its callback has this function
datanew = ExtractDataBetween(app,data,x1,x2)
where
function datanew = ExtractDataBetween(app,data,x1,x2)
% Get data between x values x1, x2
rowsNeeded=data(:,1) >= x1 & data(:,1) <= x2;
datanew = data(rowsNeeded, :);
ReportMessage(app,'Finished')
end
and
function ReportMessage(app,msg)
% Add message to textarea (acts like a log)
currString=get(app.MessagesTextArea,'Value');
cl=iscell(msg);
if cl==1
currString=[currString; msg]; %add to bottom of message box
else
currString=[currString; {char(msg)}]; %add to bottom of message box
end
app.MessagesTextArea.Value=currString;
drawnow;
scroll(app.MessagesTextArea,'bottom');
end
So I thought :
1: In order to call the function datanew from the pushbutton callback, i need app as the 1st argument
2: In order for the function ReportMessage to be called from the datanew function, again ReportMessage needs the 'app' argument
Am I totally mistaken?
So your app_ax and app.ax have lost me.
It is not possible for a parallel worker to modify the properties of the client app.
It would be possible to do,
%in client code
app_MessagesTextArea = app.MessagesTextArea;
%in parallel code
datanew = ExtractDataBetween(app_MessagesTextArea,data,x1,x2);
function datanew = ExtractDataBetween(app_MessagesTextArea,data,x1,x2)
% Get data between x values x1, x2
rowsNeeded=data(:,1) >= x1 & data(:,1) <= x2;
datanew = data(rowsNeeded, :);
ReportMessage(app_MessagesTextArea,'Finished')
end
function ReportMessage(app_MessagesTextArea,msg)
% Add message to textarea (acts like a log)
currString=get(app_MessagesTextArea,'Value');
cl=iscell(msg);
if cl==1
currString=[currString; msg]; %add to bottom of message box
else
currString=[currString; {char(msg)}]; %add to bottom of message box
end
app_MessagesTextArea.Value=currString;
drawnow;
scroll(app_MessagesTextArea,'bottom');
end
However, the app_MessagesTextArea that made it into the workers would be a copy of app.MessagesTextArea that lived by itself, and the app_MessagesTextArea.Value=currString part would not affect the original app.MessagesTextArea
You have two choices:
  1. You can save up the messages from the client and post them after the workers have finished, similar to the saved_x{i} code I showed above.
  2. You can create a parallel.pool.DataQueue or parallel.pool.PollableDataQueue and use it to send messages from the workers. The client code would use something like https://www.mathworks.com/help/parallel-computing/parallel.pool.dataqueue.aftereach.html to receive the messages and post them to the app.MessagesTextArea . See the example at https://www.mathworks.com/help/parallel-computing/parallel.pool.dataqueue.aftereach.html
Thanks Walter

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2024b

Asked:

on 7 Feb 2026

Commented:

on 8 Feb 2026 at 8:44

Community Treasure Hunt

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

Start Hunting!