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

7 次查看(过去 30 天)
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 个评论
dpb
dpb 2023-2-19
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

请先登录,再进行评论。

回答(1 个)

Sulaymon Eshkabilov
(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')

类别

Help CenterFile Exchange 中查找有关 String Parsing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by