How to call the output from gui button?
1 次查看(过去 30 天)
显示 更早的评论
Hello, here is my code
function load_data_Callback(~, ~, handles)
% hObject handle to load_data (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename, pathname] = uigetfile('*.mat','Load Image');
if filename == 0
% User clicked the Cancel button.
return;
end
fullFileName = fullfile(pathname, filename);
storedata1 = load(fullFileName);
combineFIX=storedata1.combineFIX;
set(handles.edit20,'String',[pathname filename]);
set(handles.text13,'String','it works!');
and also here
function pushbutton22_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton22 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename, pathname] = uigetfile('*.mat','Load Image');
if filename == 0
% User clicked the Cancel button.
return;
end
fullFileName = fullfile(pathname, filename);
storedata2 = load(fullFileName);
labels=storedata2.labels;
combineFIX=handles.combineFIX; %i try to call combineFIX from the button above,but it can't works
result_function; % a function that has labels and combineFIX as its input
set(handles.edit23,'String',[pathname filename]);
set(handles.text16,'String','numInst'); %numInst is the output of result_function
so, i want to call the combineFIX in the second button then do result_function and result numInst as its output. What should i do? thanks in advance.
回答(1 个)
Jan
2013-4-30
If result_function is an M-file, but not a function, it must be a script. Inside the script you cann access all variables of the caller. In your case, labels and combineFIX can be used directly. So what is the problem?
Perhaps you should convert result_function to a function (then the name would be less confusing). Add this line on top:
function numInst = result_function(labels, combineFIX)
...
Then you have defined inputs and outputs.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Workspace Variables and MAT-Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!