2017-08-01 2441 views
0

我正在使用App Designer在MATLAB GUI上工作,虽然也许我的问题类似于指南。 我想要做的是将一个回调(按钮)的输出传递给另一个。原因是随时间有效;我希望用户能够首先加载文件,然后选择要绘制的数据列。MATLAB App Designer:将输出从一个按钮传递到另一个按钮

我已经尝试建立全局变量,但似乎没有工作。

我的项目的目标是加载包含几十个“列”数据和几百行“测量”(例如:温度和湿度随时间变化)的XML文件。我的想法是,用户将按下一个按钮来加载数据,然后选择要显示的所需列。

methods (Access = private) 

    % Button pushed function: SelectNewFileButton 
    function SelectNewFileButtonPushed(app, event) 
     [filename, filepath] = uigetfile('..\*.*'); 
     app.FileNameEditField.Value=filename; 
     app.FilePathEditField_2.Value=filepath; 
    end 

    % Button pushed function: LoadDataButton 
    function LoadDataButtonPushed(app, event) 
     % Loads XML data... 
     global xHead; 
     % EM_witsfun1 is a function which takes a file name & directory as an input, and returns the header and data 
     [xHead, xData, toc1]=EM_witsfun1(app.FileNameEditField.Value,app.FilePathEditField_2.Value); 
     app.DataLoadedinsEditField.Value=toc1; % Shows elapsed time after running the above function (just to make sure it works) 
    end 

    % Button pushed function: UpdateButton 
    function UpdateButtonPushed(app, event) 
     app.ChosenChannelNameEditField.Value=xHead{app.ChooseChannelNumberEditField.Value}; 
    end 
end 

错误是:

未定义函数或变量xHead

也许有一些东西在我可以在函数内更新的函数之外定义(就像我对文本框所做的那样),但我不确定什么是最优雅的方法来做到这一点。

图片GUI显示:

Image of GUI display

+0

我相信我解决了我的问题:我不是试图建立新的全局变量,而是更新了现有GUI对象的元素。例如,通过将单元格数组的元素传递到列表框中: app.ListBox1.Items = {'newString1','newString2'}; 因此,整个应用程序都可以访问ListBox的新元素。我打算用数据做同样的事情,但我不确定如何在不显示表中的所有数据的情况下执行此操作(耗时)。 –

回答

0

我使用的公共属性,按Mathworks解决我的问题。

+0

嗨!请接受表明问题已解决的答案。更重要的是,尽管链接可能回答这个问题,但最好在这里包含解决方案的主要部分,并提供参考链接。如果链接页面更改,则仅链接答案可能会失效。 –

+0

尽管这个链接可能回答这个问题,但最好在这里包含答案的重要部分,并提供供参考的链接。如果链接页面更改,则仅链接答案可能会失效。 - [来自评论](/ review/low-quality-posts/17025091) – Jehy

相关问题