## HOW TO READ DATA FROM 4 TEXT FILES SIMULTANEOUSLY LINE BY LINE AND FIND THE MEDIAN OF EACH LINE ?

### lakshmi dwaraka (view profile)

on 18 Jan 2019
Latest activity Commented on by Rik

on 18 Jan 2019

### Rik (view profile)

i have got 4 .txt files which represents the data at 4 different times in a day, which iam attaching below. And i have to write a program such that it start reading from 17th line(after the heading pressure) in all the 4 files simulatenously. The secondlast column in all the file specifies the height and i have to find its median. so what i finally get should be the median of the height(second last colmn in each file) These 4 files should be calculated together. (For example : when these 4 files are placed sidebyside, we get 4 height data on the 17th line itself. find the median of these 4 data ..like that)
This process has to be repeated for the entire lines of the file.So finally we get about more than 500 median value. Can u pls help me write a code for this task? Iam new to matlab and have very little programming skill. ANY HELP WOULD BE MUCH APPRECIATED.PLS

### Rik (view profile)

on 18 Jan 2019

This code should do the trick:
fnames={'1OCT3AM.txt','1OCT6AM.txt','1OCT9AM.txt','1OCT12AM.txt'};
lastcol=zeros(1,numel(fnames));
n_lines_skip=16;
FormatSpec='%d %d %d %d %d %d %d %d %f %f %f %f %f';
for n_file=1:numel(fnames)
fid=fopen(fnames{n_file},'r');
lastcol(1:numel(c{end}),n_file)=c{end};
fclose(fid);
end
median_values=median(lastcol,2);

Rik

### Rik (view profile)

on 18 Jan 2019
The modification you are asking for are really basic operations. Why don't you try to learn using the tool you are working with? Any tutorial should teach you how to do this.
lakshmi dwaraka

### lakshmi dwaraka (view profile)

on 18 Jan 2019
The loop i gave seems to overwrite the median_values. so only the last iteration value is getting as output.
Thanks for the help!
Rik

on 18 Jan 2019