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

 Respuesta aceptada

Adam Danz
Adam Danz el 26 de Nov. de 2018
Editada: Adam Danz el 26 de Nov. de 2018

0 votos

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.

2 comentarios

Jwaher Alnaqbi
Jwaher Alnaqbi el 26 de Nov. de 2018
Thank you very much it worked perfictly
I used importdata() function to load the text file and it worked too!
Adam Danz
Adam Danz el 26 de Nov. de 2018
High five!

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Etiquetas

Preguntada:

el 26 de Nov. de 2018

Comentada:

el 26 de Nov. de 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by