How to open a .txt file containing a matrix in Matlab?

I am currently working on a project and have difficulty opening a .txt file in Matlab. This .txt file contains rain radar data in matrix (number) form, [m, n] = [360,90]. Below is the data I ran into.


Projection Metadata:

Radar number 54

Number of radials in scan           360

Number of range bins in scan        90

Starting range                      127500.000000

Maximum range                       150000.000000

Azimuth of first radial             -0.500000

Azimuth of last radial              359.500000

Range bin size                      250.000

Separation between radials          1.000

Projection                          POLAR

Units                               METRES DEGREES

Spheroid                            GRS80

Parameters :

Latitude of radar (degrees)         -34.017000

Longitude of radar (degrees)        151.230000

Beam elevation angle (0 for CAPPI)  0.000

Scan metadata :

Time (seconds since 01/01/1970)     973199701

Time (dd/mm/yyyy hh:mm:ss)          02/11/2000 21:15:01

Time zone (seconds ahead of UTC)    0

Time zone (hours ahead of UTC)      +0.0

Data type flag                      9

Data type                           Reflectivity

Data units                          dBZ

Not forecast data

Not simulated data

Scan data :

0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ..>1 

0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ....

0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ....

0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ....

0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ....

0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ....

0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ....

0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ....

0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ..>360

.         .          .         .         .        .         .          .        .          .

.         .          .         .         .        .         .          .        .          .

.         .          .         .         .        .         .          .        .          .

.       .          .         .         .        .         .          .        .          90

End of scan data.

      

As you can see, the first 29 text lines as well as the last text line should be skipped.

I would really love if anyone can help me open this file in Matlab as

matrix [row, column] = [360,90].

Thanks a lot for your time.

Regards, NadeaR

+2


a source to share


1 answer


You can use a MATLAB function importdata

that will read and save the file in two fields: the cell array 'textdata' for the header and matrix "data" for the next numeric data.

input = importdata('datafile.txt', ' ', 29)

      

The arguments in this example are the input file name, a space as a separator character, and the number of header lines.



Then the 360x90 matrix will be saved as input.data

.

You can use a variable as a header length argument if the number of header lines varies but is known for each file. If you don't know how many header lines to expect, you can do some fancy work in MATLAB to parse the .txt file, but at this point I preprocessed the .txt file with sed or perl, etc., and then read instead in the numeric part in MATLAB.

+2


a source







All Articles