I am currently working on the project and have a difficulty to open .txt file in Matlab. This .txt file contains rainfall radar data in matrix (numbers) form, [m,n] = [360,90]. Below is the data I am having trouble with.
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 开发者_如何学Python 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 need to be skipped.
I would be really appreciated if anybody can help me open up this file in Matlab in the form of
matrix [row,column] = [360,90].
Thank you very much for your time.
Regards, NadeaR
You can use MATLAB's importdata
function, which will read in and save the file in two fields: a cell array 'textdata' for the header and a matrix 'data' for the numerical data that follows.
input = importdata('datafile.txt', ' ', 29)
The arguments in this example are the input file name, a space as the delimiter character, and the number of header lines.
The 360x90 matrix would then be stored as input.data
.
You can use a variable as the 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 could do some fancy footwork in MATLAB to parse the .txt file but at that point, I would pre-process the .txt file with sed or perl, etc. and then read in the numerical portion in MATLAB, instead.
精彩评论