MATLAB: Load a file with gui and use it on another callback

guiload file

I want to load a file with my gui.i do this with the pushbutton(browser2).so far so good.After that i want to use this file to another pushbutton(compute) make some calculations and show the result in a static text.the problem is that after loading the file when i try to use it at pushbutton(compute) the file cant be read.So what i want is fucntion compute to read B
function browser2_Callback(hObject, eventdata, handles)
[filename pathname] = uigetfile({'*.txt'},'File Selector');
fullpathname=strcat(pathname,filename);
text = fileread(fullpathname);
set(handles.text7,'String',fullpathname)
set(handles.text8,'String',text)
filename=fullfile(fullpathname);
R=readtable(filename)
B=table2array(R)
function compute_Callback(hObject, eventdata, handles)
for i=1:1:9
x=B(i).*5;
disp(x)

Best Answer

You forgot to save the variables to the struct and to save the struct back to guidata at the end of your browser2 callback, and you forgot to actually load the variable from the struct.
function browser2_Callback(hObject, eventdata, handles)
[filename pathname] = uigetfile({'*.txt'},'File Selector');
fullpathname=strcat(pathname,filename);
text = fileread(fullpathname);
set(handles.text7,'String',fullpathname)
set(handles.text8,'String',text)
filename=fullfile(fullpathname);
R=readtable(filename)
handles.B=table2array(R)
guidata(hObject,handles)
function compute_Callback(hObject, eventdata, handles)
B=handles.B;
for i=1:1:9
x=B(i).*5;
disp(x)