parfor loop error with plotting on an image

28 views (last 30 days)
Jason
Jason on 7 Feb 2026 at 5:02
Commented: Jason on 8 Feb 2026 at 8:44
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

Walter Roberson
Walter Roberson on 7 Feb 2026 at 7:03
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
Walter Roberson
Walter Roberson on 7 Feb 2026 at 21:59
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

Sign in to comment.

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products


Release

R2024b

Community Treasure Hunt

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

Start Hunting!