Read all files in directory & append columns from each to new matrix, unrelated filenames

2 次查看(过去 30 天)
I have several text files, each with 5 columns. I want to extract two columns from each file and append those columns to a new matrix, resulting in one final matrix that holds every pair of columns from every file in my directory. The columns are not next to each other in the text files. The filenames in my directory are not named chronologically. It does not matter what order the columns are appended to the new matrix. Can I loop through the directory without using filenames at all? This is what I tried:
myFiles = uigetdir('/Users');
for i =1:length(myFiles)
newT = dlmread(myFiles(i),'\t',[1 5 2916 5]); %read one column
newPres = dlmread(myFiles(i),'\t',[1 3 2916 3]); %read another column
for j=1:length(newT)
D(j) = [newT,newPres]; %append new columns to new matrix
end
end
I am new to matlab

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by