【问题标题】:How do you open .txt file containing matrix in Matlab?如何在 Matlab 中打开包含矩阵的 .txt 文件?
【发布时间】:2011-02-13 09:44:34
【问题描述】:

我目前正在做这个项目,在 Matlab 中打开 .txt 文件有困难。 此 .txt 文件包含矩阵(数字)形式的降雨雷达数据,[m,n] = [360,90]。 以下是我遇到问题的数据。


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 个文本行以及最后一个文本行。

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

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

非常感谢您的宝贵时间。

问候, NadeaR

【问题讨论】:

    标签: matlab


    【解决方案1】:

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

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

    本示例中的参数是输入文件名、作为分隔符的空格和标题行数。

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

    如果标题行的数量不同但对于每个文件都是已知的,则可以使用变量作为 header-length 参数。如果你不知道有多少标题行,你可以在 MATLAB 中做一些花哨的工作来解析 .txt 文件,但那时,我会用 sed 或 perl 等预处理 .txt 文件,然后而是读入 MATLAB 中的数字部分。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-30
      • 1970-01-01
      • 2019-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多