import a certain text file .txt from a specific folder

22 次查看(过去 30 天)
I want to import a certain text file .txt from a specific folder.
In case the .txt file is saved in the current folder I open it this way:
import_txt = importdata('name of file.txt');
In my case I proceeded in this way but it is not the correct solution:
folder = 'C:\Users\Alberto\....'; % folder where the .txt file is located.
import_txt = importdata('name of file.txt', folder);

采纳的回答

Jean-Baptiste Lanfrey
You can try the fullfile function.
Something like this should work:
folder = 'C:\Users\Alberto\....'; % folder where the .txt file is located.
filename = fullfile(folder, 'name of file.txt');
import_txt = importdata(filename);

更多回答(1 个)

Mathieu NOE
Mathieu NOE 2022-11-23
hello again
for numerical arrays use readmatrix instead of importdata
folder = 'C:\Users\Alberto\....'; % folder where the .txt file is located.
import_txt = importdata(fullfile(folder, 'file.txt')); % or readmatrix

类别

Help CenterFile Exchange 中查找有关 Data Import and Analysis 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by