MATLAB: How can i make browse button

browse buttonloadMATLAB

I'm trying to do a browse button, i get the choose file window but after i select my file (which is not located in current folder in matlab) and click on ok, i get an error that says
Error using load
Unable to read file 'Co.txt'. No such file or directory.
while Co.txt is the file I'm trying to load which consist of columns of data
[filenameS1,pathS1]=uigetfile({'*.txt;'}, 'Choose Fisrt Sourse (S1) ');
filepathS1=fullfile('pathS1','filenameS1');
app.path = pathS1 %this is to make the path available in other callbacks
fid=fopen(filepathS1);
S1=load(filenameS1);
app.chS1=S1(:,1) %this is to make this data available in other callbacks

S1(:,1)
app.countS1=S1(:,2);%this is to make this data available in other callbacks
knowing that I'm using app designer
How can I overcome this error? thankyou

Best Answer

You've got two problems.
First, matlab can't find your file. To solve that, you either need to add the full path to your file name or you need to add the folder to your search path.
To add the path:
[filenameS1,pathS1]=uigetfile(...)
addpath(pathS1)
or to load the file with the full path
load(fullfile(pathS1, filenameS1));
Your second (potential) problem is that you're trying to load a txt file using load() which is for mat files. If your TXT file is an ASCII file then this isn't a problem.
help load
load Load data from MAT-file into workspace.
S = load(FILENAME) loads the variables from a MAT-file into a structure
array, or data from an ASCII file into a double-precision array.