Borrar filtros
Borrar filtros

I don't know why I can't open a text file?

7 visualizaciones (últimos 30 días)
Brandon
Brandon el 19 de Feb. de 2023
Comentada: dpb el 19 de Feb. de 2023
I want to open the text files, but after I download them I don't know how to open them in MATLAB, I tried using the load function but it just says
Error using load
Unable to find file or directory 'age.txt'.
Text files:
  1 comentario
dpb
dpb el 19 de Feb. de 2023
Of the options @Sulaymon Eshkabilov gives, (2) is by far the preferred solution to use as well as is creating a fully-qualified file name by using the <@doc:fullfile> function to catenate directory/folder strings to file name strings.
My personal favorite would be instead to use something more akin to
downloadDir='C:\Users\Public\Downloads'; % save the download root directory location
fn=fullfile(downloadDir,'age.txt'); % create the name
or, even easier, less data-specific
downloadDir='C:\Users\Public\Downloads'; % save the download root directory location
project='Homework'; % have a given place for the files to live
fn=fullfile(downloadDir,project,'*.txt'); % create a matching wildcard name for those wanted
d=dir(fn); % and return a dir() struct with matching files
for i=1:numel(d)
fn=fullfile(d(i).folder,d(i).name); % and get each name in turn...
%...read, process each here in turn...
...
end

Iniciar sesión para comentar.

Respuestas (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov el 19 de Feb. de 2023
(1) Do you have your downloaded file (age.txt) in your MATLAB's current directory
OR
(2) Did you show the directory address while reading the data file, e.g.:
D = readtable('C:\Users\Public\Downloads\age.txt')
OR
(3) Did you added the path of the directory where age.txt file is residing, e.g.:
addpath('C:\Users\Public\Downloads')
D = readtable('age.txt')

Categorías

Más información sobre String Parsing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by