I don't know why I can't open a text file?
8 次查看(过去 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:
systolic_bp.txtDownload systolic_bp.txt
diastolic_bp.txtDownload diastolic_bp.txt
1 个评论
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
2023-2-19
(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')
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!