How to call the output from gui button?

1 次查看(过去 30 天)
Tara
Tara 2013-4-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.
  3 个评论
Jan
Jan 2013-4-30
编辑:Jan 2013-4-30
What does "call the combineFIX" mean? What is "combineFIX" and what does "can't work" exactly mean?
I do not understand this also:
result_function; % a function that has labels and combineFIX as its input
No, result_function does not have any inputs.
Tara
Tara 2013-4-30
combineFIX is a variable from .mat file in the load_data, and labels is a variable from .mat file in the pushbutton22. sorry, i mean result_function isn't a function, but it is M file, result_function.m that has variable combineFIX and labels. to display numInst from that result_function, i need combineFIX and also labels. so, how can i display the numInst from the pushbutton22?

请先登录,再进行评论。

回答(1 个)

Jan
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.
  1 个评论
Tara
Tara 2013-5-1
my code doesn't work. it says
??? Reference to non-existent field 'combineFIX'.
Error in ==> guifix>pushbutton22_Callback at 836
combineFIX=handles.combineFIX;

请先登录,再进行评论。

类别

Help CenterFile 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!

Translated by