import a certain text file .txt from a specific folder

조회 수: 18 (최근 30일)
Alberto Acri
Alberto Acri 2022년 11월 23일
답변: Mathieu NOE 2022년 11월 23일
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
Jean-Baptiste Lanfrey 2022년 11월 23일
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에서 Text Files에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by