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

조회 수: 15 (최근 30일)
Brandon
Brandon 2023년 2월 19일
댓글: dpb 2023년 2월 19일
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
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')

카테고리

Help CenterFile Exchange에서 Downloads에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by