MATLAB Answers

How do I read multiple text files and use its data for mathematical Calculation?

1 view (last 30 days)
mujtabaxaidi
mujtabaxaidi on 14 Sep 2021
Answered: Walter Roberson on 15 Sep 2021
I have approximately 60 files for input signal and 60 files for Reference signal and I need the values stored in these files to calculate Transmission coeffiecient wrt time. Files contain data as follow
0, 102
2,11
and so on.
It will be great if someone can help me out.

Answers (1)

Walter Roberson
Walter Roberson on 15 Sep 2021
ext = '.txt'; %extension of files
dinfo = dir("*" + ext);
filenames = {dinfo.name};
nfiles = length(filenames);
all_data = cell(nfiles,1);
for K = 1 : nfiles
thisfile = filenames{K};
thisdata = load(thisfile);
all_data{K} = thisdata;
end
The data is now in the cell array all_data .
Or you could process the data as you read it.

Tags

Products

Community Treasure Hunt

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

Start Hunting!