如何在Matlab中打开包含矩阵的

如何在Matlab中打开包含矩阵的

本文介绍了如何在Matlab中打开包含矩阵的.txt文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在从事该项目,并且在Matlab中打开.txt文件有困难.该.txt文件包含矩阵(数字)形式的降雨雷达数据[m,n] = [360,90].以下是我遇到的数据.

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          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.

您会看到前29个文本行以及最后一个文本行都需要跳过.

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

如果有人可以帮助我以Matlab形式打开此文件,我将不胜感激

I would be really appreciated if anybody can help me open up this file in Matlab in the form of

矩阵[行,列] = [360,90].

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

非常感谢您的宝贵时间.

Thank you very much for your time.

关于,NadeaR

Regards,NadeaR

推荐答案

您可以使用MATLAB的importdata函数,该函数将在两个字段中读取并保存文件:用于标题的单元格数组'textdata'和一个矩阵后面的数字数据的数据".

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.

然后将360x90矩阵存储为input.data.

The 360x90 matrix would then be stored as input.data.

如果标题行的数量有所不同,但对于每个文件都是已知的,则可以将变量用作标题长度参数.如果您不希望看到多少行标题,则可以在MATLAB中做一些花哨的操作来解析.txt文件,但是到那时,我将使用sed或perl等对.txt文件进行预处理,然后而是在MATLAB中读取数值部分.

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.

这篇关于如何在Matlab中打开包含矩阵的.txt文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 09:06