How to acces app data from output function

2 次查看(过去 30 天)
Hi,
I'm building a Matlab app with the appdesigner. This app runs an optimization using the genetic algorithm and i'm trying to implement a stop button. The problem I'm having is that the output function belonging to my optimization algorithm, that should stop my optimization, should acces data from my application which does not work.
I tried making a public propertie called 'Stop_opt' and accessing it as 'app.Stop_opt'. I tried writing the 'Stop_opt' variable to the Matlab workspace. I also tried setappdata. All of these options do not seem to work. I keep getting the same error 'Undefined variable'.
Can anyone explain to me how I get my output function to acces a variable from my appdesigner app?
Kind regards,
Wouter
  5 个评论
Reshma Nerella
Reshma Nerella 2020-3-13
Hi,
The question looks a bit vague. Can you provide the custom code so that we could debug.
Mohammad Sami
Mohammad Sami 2020-3-16
编辑:Guillaume 2020-3-16
I assume that you have written a function "outputfunction" that you call from inside a callback in your appdesigner app.
Outputfunction I assume is running some kind of loop that is infinite. Now you want this output function to stop running when you press a stop button in your GUI.
To do this add a state button to your app designer called stop.
Modify your outputfunction to accept app as an additional argument. This will allow your output function to access the public properties of your app. Otherwise there is no way for this function to access your app.
function outputfunction(.....args, app)
while (app.stopbutton.value ~= 1)
% do optimising
end
end
edited by Guillaume: formatted code as code

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Genetic Algorithm 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by