フィルターのクリア

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

13 ビュー (過去 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 Center および File ExchangeString Parsing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by