Using for loop to enter data with similar names
1 次查看(过去 30 天)
显示 更早的评论
I am trying to import data from 250 *.txt files. The file names are as such "C58501_line_ssf_001" to "C58501_line_ssf_250".
numfiles = 250;
filenames = 'C58501_line_ssf_%.txt'
results = cell(numfiles, 1);
for K = 1 : numfiles
modpath = filenames{K};
datastruct = load(modpath);
end
these files have multiple data rows for 55 individual paths. I want to import these *.txt files, extract the data from paths 16-20 and then get the individual values from 3 seperate columns. I am very uncertain on how to import all the data files and eliminate data down to the rows and columns I need.
Thank you in advance!
7 个评论
Bob Thompson
2018-3-27
See comments on your other question.
For gathering multiple files you can also look at using the uigetfile() command. It only allows you to select from one directory at a time, but you are able to pick multiple files which it will index in a cell array of strings.
If the files are not able to be moved to a single directory then changing the string using sprintf and a for loop like you have is probably your best bet.
回答(1 个)
Jan
2018-3-28
C = cell(1, 250);
for k = 1:250
Filename = sprintf('C58501_line_ssF_%04d.txt',k);
M = dlmread(Filename,' ',1,0);
C{k} = M(ismember(M(:,1), 16:20), [1,2,3,6]);
end
Result = cat(1, C{:});
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Workspace Variables and MAT-Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!