|
|
Joining Multiple Data Files
I have several binary data files (daily temperature) organized by year, month and day. I would like to create a single data file for average monthly temperature. For example the march and April 2010 files are:
abc_20100301
abs_20103002
abc_20100303
......
abc_20100331
abc_20100401
abs_20100402
abc_20100403
......
abc_20100430
Each file is made of three columns: lat lon and temp
My final data file should lool like: Lat lon year Mar Apr...., where Mar and Apr are average temperature (temp variable) for march and april.
I will appreciate any help.
|
|
0
|
|
|
|
Reply
|
Joseph
|
3/20/2011 6:42:03 PM |
|
"Joseph Kaba" wrote in message <im5hpr$ilg$1@fred.mathworks.com>...
> I have several binary data files (daily temperature) organized by year, month and day. I would like to create a single data file for average monthly temperature. For example the march and April 2010 files are:
> abc_20100301
> abs_20103002
> abc_20100303
> .....
> abc_20100331
> abc_20100401
> abs_20100402
> abc_20100403
> .....
> abc_20100430
>
> Each file is made of three columns: lat lon and temp
> My final data file should lool like: Lat lon year Mar Apr...., where Mar and Apr are average temperature (temp variable) for march and april.
>
> I will appreciate any help.
Are the lat and lon information the exact same in each file? If so you could just set up a final matrix and run a loop taking the temp data from the individual files and adding it to that file... something like this depending on what your files are and how you open them.
files=dir('abc_*');
final(:,1)=lat;
final(:,2)=lon;
final(:,3)=year;
for i=1:size(files)
the_file=load(files(i).name);
final(:,i+3)=the_file(:,3);
end
|
|
0
|
|
|
|
Reply
|
Steve
|
3/20/2011 7:03:04 PM
|
|
Joseph Kaba wrote:
> I have several binary data files (daily temperature) organized by year,
> month and day. I would like to create a single data file for average
> monthly temperature. For example the march and April 2010 files are:
> abc_20100301
> abs_20103002
> abc_20100303
> .....
> abc_20100331
> abc_20100401
> abs_20100402
> abc_20100403
> .....
> abc_20100430
>
> Each file is made of three columns: lat lon and temp
> My final data file should lool like: Lat lon year Mar Apr...., where Mar
> and Apr are average temperature (temp variable) for march and april.
> I will appreciate any help.
Joseph,
Why do you call them binary files? Do they have raw data in
double/integers? If so, you can use FOPEN and FREAD (with the curret
precision for the size of each 'column).
If you can open these files in a text editor and look at the values, the
data is stored as plain text (ASCII). You can use FSCANF after you FOPEN
to read these numbers.
You could set up a loop for each month: (air code)
avgMonthlyTemp = zeros(1,12);
for month=1:12
baseFileName = ['abc_2010' sprintf('%0.2d',month)];
allMonthsFiels = dir([baseFileName '*']);
for fileInd = 1:length(allMonthsFiles)
fileName = allMonthsFiles(fileInd).name;
<your code to read and average the data>
end
avgMonthlyTemp(month) = <>;
end
%Loop up FOPEN in 'w' or 'wt' mode along with FPRINTF/FWRITE to write
out the data.
Subsequently, you can use FPRINT (to write text) or FWRITE(to write
binary) to create your output files.
(The doc/help pages for the functions in bold will have examples to get
you started, if you need more help, post back).
|
|
0
|
|
|
|
Reply
|
Ashish
|
3/21/2011 1:54:45 PM
|
|
|
2 Replies
261 Views
(page loaded in 0.036 seconds)
|
|
|
|
|
|
|
|
|