How can I systematically extract data from dat files?

2 views (last 30 days)
Hello, I'm looking for someone to help me out with dlmread.
I have a series of ".dat" files (S1.dat, S2.dat, ....S65.dat), from which I will need to extract values from certain cells. Each file has 251 rows and 105 columns. Currently I use a very inefficient way to do it (as an example):
I first read each dat file into a variable "M{i}"
M1=dlmread('S1.dat');
I then extract values from target cells and dump them into a new variable "A{i}"
A1=[M1([99],[62]) M1([121],[62]) M1([60],[82]) max(M1([77:84],[82])) sum(M1([84:104],[101])) sum(M1([25:45],[101]))];
And I manually repeat these two lines of codes for all the files by changing "M1/S1" to "M2/S2", "M3/S3", and so on. I believe there is a much more efficient way to accomplish this using some loop coding. Ideally, I want to be able to do something like the following so I can extract values from all files and write them into separate variables at once:
i=65;
M{i}=dlmread('S{i}.dat');
A{i}=[M{i}([99],[62]) M{i}([121],[62]) M{i}([60],[82]) max(M{i}([77:84],[82])) sum(M{i}([84:104],[101])) sum(M{i}([25:45],[101]))];
However, I couldn't seem to work that out. I would appreciate any advice/help on this.
Thank you!
Teng

Answers (0)

Categories

Find more on App Building in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!