From: Harpreet on
%% Moving window average for generating seismic data from porosity
distribution of 5 wells
clear all;
clc;

%% Reading porosity distributions (with 5 wells only) through .dat
file generated by SGEMS

poro_5wells_gslib=textread('poro models_gslib.dat','%f
\t','headerlines',102);
poro_5wells_gslib=reshape(poro_5wells_gslib,100,2500)';

%% Taking moving window average with function (code)
moving_average2.m

avg_seismic_data=moving_average2(poro_5wells_gslib,5,5); % window
average of (2x5+1) by (2x5+1)

From above Matlab code I generate the 2500 rows x 100 columns seismic
data in variable named avg_seismic_data. I want to save the values of
this variable in a text (.dat) file which must have 102 header lines
in the following manner:

avg_seismic_data_models
100
avg_seismic_data_models_1
avg_seismic_data_models_2
avg_seismic_data_models_3
.
.
.
.
.
avg_seismic_data_models_100

In the above header style, the first line is the name of the file, the
2nd line tells the number of columns (each column has 2500 rows) in
Matlab variable avg_seismic_data, and the rest of the 100 lines
represent the name of the columns in avg_seismic_data (100 columns are
the 100 realizations).

On internet search I found the function 'dlmwrite', however I could
not obtain the desired result. Till now I have to manually write the
headers and then add the data at the end in the .dat file.

Thank you if you help.

From: dpb on
Harpreet wrote:
....

> On internet search I found the function 'dlmwrite', however I could
> not obtain the desired result. Till now I have to manually write the
> headers and then add the data at the end in the .dat file.

The Matlab function help would undoubtedly be of more direct use than a
full internet search...

help iofun % for overview

help fprintf % for specifics for your application is probably best bet

Put the header information in a cell array or write it directly in a
loop w/ '%s\n' as a format; if need the number embedded somewhere in the
string that's either a num2str() operation to build a string first or
the use of a numeric field in the appropriate format string.

You can build whatever you need altho when you get to writing the data
remember that Matlab storage order is column major so you may (will)
want to transpose on write to generate the output in expected visual order.

--

From: Harpreet on
On Jul 3, 3:27 pm, dpb <n...(a)non.net> wrote:
> Harpreet wrote:
>
> ...
>
> > On internet search I found the function 'dlmwrite', however I could
> > not obtain the desired result. Till now I have to manually write the
> > headers and then add the data at the end in the .dat file.
>
> The Matlab function help would undoubtedly be of more direct use than a
> full internet search...
>
> help iofun  % for overview
>
> help fprintf % for specifics for your application is probably best bet
>
> Put the header information in a cell array or write it directly in a
> loop w/ '%s\n' as a format; if need the number embedded somewhere in the
> string that's either a num2str() operation to build a string first or
> the use of a numeric field in the appropriate format string.
>
> You can build whatever you need altho when you get to writing the data
> remember that Matlab storage order is column major so you may (will)
> want to transpose on write to generate the output in expected visual order.
>
> --

Thanks dpb.

Its good till what you suggested. Now when I want to write the
required data (2500 x 100) after writing the headers, I get the data
in form of one row only (250000 data points in that row). Can you
suggest how to change those 250000 data in array format of 2500 x 100,
following the headers in .dat file?
From: dpb on
Harpreet wrote:
....

> Its good till what you suggested. Now when I want to write the
> required data (2500 x 100) after writing the headers, I get the data
> in form of one row only (250000 data points in that row). Can you
> suggest how to change those 250000 data in array format of 2500 x 100,
> following the headers in .dat file?

Now for the pita part of C formatting...

nPerLine = 100;
fmt = [repmat('%f ',nPerLine,1) \n'];
fprintf(fmt, x');

Build fmt at the command line (perhaps w/ nPerLine=5, say) to see what's
going on. One of my favorite pet peeves requires this--no repeat
specifier is available. :( Also, one has to explicitly code the
newline at the right position in the file.

I've asked before for TMW to figure out a way to incorporate the
equivalent of the Fortran repeat specifier wherein above would be
100Fw.d/ but hasn't happened. Failing that there doesn't seem to be any
way to do so w/o apparently insurmountable parsing problems, I offered
that one should be able to give a desired shape and have fprintf "do the
right thing (tm)" automagically but that hasn't happened, either...

Last time I made any suggestions several years ago was treated most
rudely as not having a current license so I'll not be doing that again... :(

--
From: Harpreet on
On Jul 3, 8:11 pm, dpb <n...(a)non.net> wrote:
> Harpreet wrote:
>
> ...
>
> > Its good till what you suggested. Now when I want to write the
> > required data (2500 x 100) after writing the headers, I get the data
> > in form of one row only (250000 data points in that row). Can you
> > suggest how to change those 250000 data in array format of 2500 x 100,
> > following the headers in .dat file?
>
> Now for the pita part of C formatting...
>
> nPerLine = 100;
> fmt = [repmat('%f ',nPerLine,1) \n'];
> fprintf(fmt, x');
>
> Build fmt at the command line (perhaps w/ nPerLine=5, say) to see what's
> going on.  One of my favorite pet peeves requires this--no repeat
> specifier is available.  :(  Also, one has to explicitly code the
> newline at the right position in the file.
>
> I've asked before for TMW to figure out a way to incorporate the
> equivalent of the Fortran repeat specifier wherein above would be
> 100Fw.d/ but hasn't happened.  Failing that there doesn't seem to be any
> way to do so w/o apparently insurmountable parsing problems, I offered
> that one should be able to give a desired shape and have fprintf "do the
> right thing (tm)" automagically but that hasn't happened, either...
>
> Last time I made any suggestions several years ago was treated most
> rudely as not having a current license so I'll not be doing that again... :(
>
> --

Thank you very much. Appreciate it.
 | 
Pages: 1
Prev: image registration
Next: i need urgent help