I need to load multiple files and extract one value from each file into an output file

2 ビュー (過去 30 日間)
Adriana Amrhein
Adriana Amrhein 2021 年 10 月 6 日
回答済み: Prateek Rai 2021 年 10 月 9 日
I have 300 files containing 8000 columns and 16 rows. I need to read in each file and extract the value from column 1300 row 14. I want to extract all these values into one output file. Can anyone help? Thanks!
  4 件のコメント
_
_ 2021 年 10 月 6 日
Then you should be able to use load to read the files:
% fn is assumed to be a cell array containing your 300 file names (full paths)
data = zeros(1,300);
for i = 1:300
new_data = load(fn{i});
data(i) = new_data(14,3000);
end
And then fopen, fprintf, etc., to write your output file.

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

回答 (1 件)

Prateek Rai
Prateek Rai 2021 年 10 月 9 日
To my understanding, you have 300 text files containing 8000 columns and 16 rows and you want to read data of column 1300 row 14 from each file.
% input to tabularTextDatastore will be the location of the folder where you have your text files
dts = tabularTextDatastore('Location of the folder containing text files');
files = dts.Files;
% data will store the data of column 1300 row 16 from each text files
data = zeros(300,1);
% for loop to read the data from every text files
for i = 1:1:length(files)
file_i = load(files{i});
data(i) = file_i(14,1300);
end
You can refer to tabularTextDatastore MathWorks Documentation page to learn more on datastore for tabular text files.

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by