Read all files in directory & append columns from each to new matrix, unrelated filenames
2 views (last 30 days)
Show older comments
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 Comments
Answers (0)
See Also
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!