MATLAB: Importing and reading txt file in GUI

import txt filematlab gui

hello i'm new in MATLAB GUI ,i just wanna know how to import a txt file in GUI and then use it for calculations
my Gui contains 2 pushbutton and a static text for displaying the result ,if any one can help i will be grateful
the file i want to import is a txt file with 2 columns "TimexValues" with 8000 data pts
thank you.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (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({'*.txt'},'File Selector');
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

Best Answer

function pushbutton1_Callback(hObject, eventdata, handles)
[filename, pathname] = uigetfile({'*.txt'},'File Selector');
if ~ischar(filename)
return; % User aborted the file selection
end
file = fullfile(pathname, filename);
[fid, msg] = fopen(file, 'r');
if fid == -1
error(msg);
end
Data = fscanf(fid, '%g %g\n', [2, inf]); % Or how your file is formatted
fclose(fid);
handles.Data = Data;
guidata(hObject, handles); % Store updated handles struct in the GUI
end
function pushbutton2_Callback(hObject, eventdata, handles)
plot(handles.Data); % Or what ever you want to do
end