Multiple instances of gui when calling from external function

I have an external Matlab function that I wish to produce continuously update plots in the GUI created by app designer.
To get the external function to plot on the app GUI (named betaine.mlapp) I created the following public function in the app code space:
methods (Access = public)
function results = plotfit(app,x,y1,y2)
plot(app.UIAxes,x,y1);
hold(app.UIAxes);
plot(app.UIAxes,x,y2,'-b');
results = 0;
end
end
from the external function (*.m) (yo is the observed spectrum, yc is the calculated spectrum):
x = 1:m;
a = betaine;
z = plotfit(a,x,yo,yc);
It plots just fine, but every time it calls plotfit it generates a new instance of the app gui. It does this hundreds of times. How can I get it to continuously update the on the same gui?

3 件のコメント

Geoff Hayes
Geoff Hayes 2019 年 2 月 13 日
Dennis - what is
a = betaine;
? Are you creating a new instance of your app (named betaine?) everytime you call this external function?
Geoff Hayes
Geoff Hayes 2019 年 2 月 13 日
Dennis' answer moved here
Geoff --
That must be what is happening, but I don't know how to get around it. The plot function is in the app code space, and each time that it is called from an external function it creates a new instance of the app.
Thanks
Geoff Hayes
Geoff Hayes 2019 年 2 月 13 日
Dennis - perhaps you can re-use the a whenever you call that external function again? Or create the GUI just once - outside of your external function - and then pass this in as an input to your external function. So each time you call the external function (however you do this) you just pass in the GUI that you have already created and it is that GUI that you will call plotfit on. (You may need to post your external function or at least its signature and how you call it so that we can get a better idea of how it is used.)

サインインしてコメントする。

回答 (1 件)

Dennis Bennett
Dennis Bennett 2019 年 2 月 13 日

0 投票

Geoff, Thanks. I think I figured it out, but I won't be able to try it out tomorrow: A chain of external functions are called from the app. One of those functions needs to access the app plot functions. I think that all I have to do is pass the app handles into the external function, and I can the call the app plot functions from the external function. Does this sound reasonable?

1 件のコメント

Geoff Hayes
Geoff Hayes 2019 年 2 月 14 日
Dennis - yes, this sounds reasonable. Good luck!

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeDevelop Apps Using App Designer についてさらに検索

製品

リリース

R2018a

質問済み:

2019 年 2 月 13 日

コメント済み:

2019 年 2 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by