Carrying variables and matrices between GUIs

2 ビュー (過去 30 日間)
Kamuran
Kamuran 2015 年 5 月 10 日
コメント済み: Image Analyst 2015 年 5 月 10 日
Hello,
Is there a way to carry variable between GUIs. I am calling a GUI inside another GUI. I want to carry variables from the first on to the second one. For example
First GUI
Function1
Function2
.
.
.
Call the second GUI ( I want to access some of the results from above functions) and I don't want to save and load the data.
Is there a way of doing this?
Thanks

採用された回答

Walter Roberson
Walter Roberson 2015 年 5 月 10 日
Yes, a GUI is a function, and you can define the function with as many parameters as you need and pass the parameters from the first GUI.

その他の回答 (1 件)

Image Analyst
Image Analyst 2015 年 5 月 10 日
Just pass them in the argument list.
function FirstGUI()
% Call a couple of functions defined inside FirstGUI.m
Function1();
Function2();
% Now, call the the second GUI, passing it some arguments...
[output1, output2] = SecondGUI(input1, input2, input3);
In the OpeningFcn() of the second GUI, look at varargin to extract the various inputs and do something with them, like send their values to properties of various widgets on the interface, or whatever you want.
  5 件のコメント
Walter Roberson
Walter Roberson 2015 年 5 月 10 日
編集済み: Walter Roberson 2015 年 5 月 10 日
Why not pass them all in one matrix in the first place?
If the matrices might be different size or data types, use a cell array instead of a numeric array. or use a structure.
varstopass = struct{'input1', input1, 'input2', input2, 'input3', input3);
then pass in varstopass, and afterwards you can use varstopass.input1 and so on.
Image Analyst
Image Analyst 2015 年 5 月 10 日
Good idea, and that's what I do. Any user settings that I need to pass around to different functions (ones that are not simply GUI properties), I just attach as fields to a structure I call UserSettings and then pass that around. The Mathworks recommends attaching to the "handles" structure but the handles structure already has so many other things on it that I don't want to clutter it up with my stuff.

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

カテゴリ

Help Center および File ExchangeWhos についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by