MATLAB Answers

0

How to call function in matlab appdesigner under parforloop

I can not call function under parforloop in matlab appdesigner. It's showing me the following error: Functionality not supported with figures created with the uifigure function. Here is my code
function func1(app)
disp(strcat('Function 1----',datestr(now)));
pause(2);
disp(strcat('Function 1----',datestr(now)));
end
function func2(app)
disp(strcat('Function 2----',datestr(now)));
pause(2);
disp(strcat('Function 2----',datestr(now)));
end
function StartAutomationButtonPushed(app, event)
parfor i = 1:2
if i == 1
func1(app);
else
func2(app);
end
end
end

  0 Comments

Sign in to comment.

1 Answer

Answer by Ashadullah Shawon on 19 Jul 2019
 Accepted Answer

After lots of try, finally i have solved this. So i am posting the answer for the others. Use parallel.pool.DataQueue and afterEach function to solve this problem. Here is the working code and i have also uploaded the full appdesigner file here.
methods (Access = private)
function app= func1(app,data)
%disp(data);
app.textTextArea.Value = strcat('Function 1----',datestr(now));
%pause(1);
app.textTextArea.Value = [app.textTextArea.Value;strcat('Function 1----',datestr(now))];
end
function app= func2(app,data)
%disp('Function 2');
app.textTextArea.Value = [app.textTextArea.Value;strcat('Function 2----',datestr(now))];
%pause(1);
app.textTextArea.Value = [app.textTextArea.Value;strcat('Function 2----',datestr(now))];
end
end
methods (Access = private)
% Value changed function: ClickOnButton
function ClickOnButtonValueChanged(app, event)
q = parallel.pool.DataQueue;
r = parallel.pool.DataQueue;
afterEach(q, @app.func1);
afterEach(r, @app.func2);
parfor i = 1:2
if i == 1
%func1(app);
send(q,i);
else
%func2(app);
send(r,i);
end
end
end
end

  0 Comments

Sign in to comment.