Write txt to table with collumn name
조회 수: 3 (최근 30일)
이전 댓글 표시
Hello,
I need to go through 100 folders -> take txt file (name of the file is the same for all folders) and write it to table. The txt file contains only one collum with value I need to import to table for all folder, so one folder one collum, but only values greater than 0. I'm wondering, is there a way that the name of collum would be name of folder from which I import files values? I would appreciate if someone could take the time to help me, I'm new to MATLAB. Thank you
댓글 수: 0
답변 (2개)
Peter Perkins
2022년 3월 2일
Sarah, you question is a little vague. It sounds like you have a series of folders, let's say they are named folder1, folder2, ... folder100. And in each one there's a text file named data.txt, and every data.txt contains one column of numbers. If that's not what you have then please be more specific and provide a short, clear example.
It sounds like you need to write a loop over the folders, perhaps using dir, then read data.txt using readtable or readmatrix, then combine all those results. I would recommend readmatrix if you have a recent enough MATLAB, and then at each iteration of the loop, you would do something like
t = table;
for i = 1:length(folders)
foldername = folders{i}; % assuming you have the folder names in a cell array of char vectors
x = readmatrix('data.txt', ...);
t.(foldername) = x;
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Whos에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!