【发布时间】:2018-10-29 20:18:59
【问题描述】:
我正在编写一个简单的 GUI,它必须完成 2 个任务:
1-为一个txt文件导入一组数据
2- 使用之前导入的数据进行一些计算
两个任务都是按一个按钮来执行的,每个任务一个按钮。
对于“加载数据”按钮(任务 1),我在该按钮的回调中使用了 uiimport 命令(如此处所述 Matlab Calling 'Import Data' with GUI Button):
S = uiimport('-file');
数据作为“191384x3 双精度”加载。 我还修改了如下功能,以便让 S 可用于第二个按钮:
function S = load_data_Callback(hObject, eventdata, handles)
然后我按下第二个按钮来执行第二个任务。在我写的第二个按钮的回调中
function pushbutton2_Callback(hObject, eventdata, handles, S)
loaded_data = S; % to access the data in the non structured array
% Then I want to have 3 separate vectors out of the structure
v1 = loaded_data(:,1);
v2 = loaded_data(:,2);
v3 = loaded_data(:,3);
当我按下第二个按钮时,我收到一条错误消息:
Not enough input arguments.
loaded_data = S;
Error in gui_mainfcn (line 95)
feval(varargin{:});
我错过了什么?
【问题讨论】:
-
回调函数有一个特定的定义,你不能随意添加输入或输出参数。
load_data_Callback必须在 UI 中保存数据,pushbutton2_Callback必须从保存位置获取数据。例如,您可以使用mathworks.com/help/matlab/ref/guidata.html 或mathworks.com/help/matlab/ref/getappdata.html
标签: matlab user-interface