Update app axes in background using parfeval

5 views (last 30 days)
I am designing an app with multiple axes that need to operate independently and simultaneously. I'm trying to use parfeval to run these updates in the background with no success. The true app is more complicated so here is a simple code example to illustrate my problem. There are 2 UIAxes and with a button for each to start the calculations.
% Callback for button to display signal in 1st set of axes
function StartButton1Pushed(app, event)
for i=1:100
f = parfeval(backgroundPool,@updateAx1,0,app);
end
end
% Callback for button to do "other stuff" in second axis
function StartButton2Pushed(app, event)
for i=1:100
updateAx2(app)
end
end
% Plot random data in 1st axis
function updateAx1(app)
xdata = rand(100,1);
plot(app.ax1,xdata)
drawnow
end
% Plot random data in 2nd axis
function updateAx2(app)
xdata = rand(100,1);
plot(app.ax2,xdata)
drawnow
end
Essentially, one UIAxes needs to display a stream of signal data while "other stuff" is happening in the other UIAxes. I don't need to calculate anything in the signal axes; the data are already in the workspace. I just need the axes to continually update in the background. Whenever I try to use parfeval with or without an afterEach function, nothing happens.
  2 Comments
Mario Malic
Mario Malic on 8 Sep 2022
Hey Tim,
I have never used parfeval but I would suggest you to try to do any change to the app first once the parfeval is running just to check if it's possible to do so.
function StartButton2Pushed(app, event)
% Change a value in numeric field or anything
app.EditField.Value = 1;
end
I have used dataqueues to update my UIs in parallel and when I did so, I couldn't pass app to workers as it has to be saved (not sure if it is possible to do so now). Try finding app handle in the updateAx1 without sending it app as an argument
% % Find app
% I have set the tag specifically so I can find it easier
app = get(findall(0, 'Tag', 'AppUIFigure'), 'RunningAppInstance');
Alvaro
Alvaro on 23 Jan 2023
Does your app work without introducing parallelization?

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 23 Jan 2023
parallel workers never have access to the display graphics
You would need to use a parallel data queue to send values back to the client.
In theory you can construct graphic objects in a worker and send them through a queue. The client might then have to set the Parent of the received object.

Categories

Find more on Asynchronous Parallel Programming in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!