晚上好人,
我想知道如何在matlab中将变量从按钮传递到另一个按钮。这是我的代码:
function pushbutton4_Callback(hObject, eventdata, handles)
[filename, pathname] = uigetfile('*.*', 'Pick a MATLAB code file','MultiSelect', 'on');
fullfilename=fullfile(pathname,filename);
b=importdata(fullfilename);
set(handles.edit7,'string',fullfilename);
function pushbutton5_Callback(hObject, eventdata, handles)
mamamoa=load('best_network.mat');
A=mamaoa(b);
set(handles.edit1,'string',A);
变量b是函数pushbutton5中要知道的变量。
答案 0 :(得分:0)
您可以将变量b
保存在图中的appdata
内。
function pushbutton4_Callback(hObject, eventdata, handles)
[filename, pathname] = uigetfile('*.*', 'Pick a MATLAB code file','MultiSelect', 'on');
fullfilename = fullfile(pathname,filename);
b = importdata(fullfilename);
set(handles.edit7, 'string', fullfilename);
%// Store b within the appdata
setappdata(handles.hfig, 'b', b);
end
function pushbutton5_Callback(hObject, eventdata, handles)
mamamoa = load('best_network.mat');
%// Retrieve b from the appdata
b = getappdata(handles.hfig, 'b');
A = mamaoa(b);
set(handles.edit1,'string',A);
end
或者,您可以使用guidata
和handles
结构存储数据,但不建议将其用于非常大量的数据,因为您会注意到性能受损。
function pushbutton4_Callback(hObject, eventdata, handles)
[filename, pathname] = uigetfile('*.*', 'Pick a MATLAB code file','MultiSelect', 'on');
fullfilename = fullfile(pathname,filename);
%// Store it within handles.b
handles.b = importdata(fullfilename);
set(handles.edit7, 'string', fullfilename);
%// Update the guidata
guidata(handles.hfig, handles);
end
function pushbutton5_Callback(hObject, eventdata, handles)
mamamoa = load('best_network.mat');
A = mamaoa(handles.b);
set(handles.edit1,'string',A);
end