Extract rows separately from multiple files.

1 回表示 (過去 30 日間)
C Smyth
C Smyth 2017 年 12 月 13 日
コメント済み: Jan 2017 年 12 月 14 日
I have 90 files each with three columns and about 2000 rows of data. I want to match/extract the first row in each of the files together, then the second, then the third and so on. Anyone know an efficient way of doing this? Thanks
  1 件のコメント
Jan
Jan 2017 年 12 月 13 日
It would be useful if you mention, in which format the files are written. It matters if they are MAT files, JPEG or text files.

サインインしてコメントする。

回答 (1 件)

Jan
Jan 2017 年 12 月 13 日
The most efficient way is to read all files into an array and sort the data as you want.
To get a more explicit answer, please explain what "match/extract the first row in each of the files together" means. Without knowing this detail, an answer must remain very vague.
  2 件のコメント
C Smyth
C Smyth 2017 年 12 月 14 日
Thank you for your reply! When I say match/extract, I want to input the first row of each file into an equation, then repeat the equation with the second row of each file and so on. But instead of re-writing the equation is there a way to automatically do this. All of the files are MAT files. I hope this makes more sense. Thank you
Jan
Jan 2017 年 12 月 14 日
Load all files in a loop:
Folder = 'C:\Temp'; % Adjust this
DirList = dir(fullfile(Folder, '*.mat'));
nData = numel(DirList);
Data = cell(1, nData);
for k = 1:nData
FileData = load(fullfile(Folder, DirList(k).name));
Data{k} = FileData; % Or FileData.YourField, adjust this
end
Now you can process the data in a loop:
for kRow = 1:nRows
Row = zeros(nData, ???);
for kData = 1:nData
Row(kData, :) = Data{kData}(kRow, :);
end
... Do what you want with the Row data...
end
This is based on some guessing and assuming, because you did provide very few details only. But maybe the general idea gets clear.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by