简体   繁体   English

在八度中读取文本文件时出错

[英]error reading a text file in octave

I have a text file named xMat.txt which has 200 space separated elements in one line and some 767 lines. 我有一个名为xMat.txt的文本文件,该文件在xMat.txt中有200个空格分隔的元素,在某些行中有767行。

This is how xMat.txt looks. 这就是xMat.txt外观。

386.0 386.0 388.0 394.0 402.0 413.0 ... .0 800.0 799.0 796
801.0 799.0 799.0 802.0 802.0 80 ... 399.0 397.0 394.0 391
.
.
.

When I try to read the file in octave using X = dlmread('xMat.txt',' ') I get a matrix of size 767 X 610 . 当我尝试使用X = dlmread('xMat.txt',' ')以八度为单位读取文件时,得到的矩阵大小为767 X 610 I am expecting a matrix of size 767 X 200 since there are 200 elements in one row. 我希望矩阵的大小为767 X 200因为一行中有200个元素。 How can I solve this problem? 我怎么解决这个问题?

Edit - This is my file 编辑- 这是我的文件

Your uploaded file https://bpaste.net/raw/96cf21aa21b8 has incosistent number of columns per row. 您上传的文件https://bpaste.net/raw/96cf21aa21b8每行的列数惊人。

$ awk "{print NF}" tmp | sort | uniq -c
      2 200
    754 201
      1 206
      1 217
      1 223
      1 234
      1 237
      1 238
      1 269
      1 273
      1 390
      1 420
      1 610

So the most rows have 201 columns but one has 420 columns and one even has 610 columns. 因此,最多的行有201列,但一排有420列,一排甚至有610列。 This is the reason you get a 767x610 matrix from dlmread. 这就是从dlmread获得767x610矩阵的原因。

Lets look which lines have more than 201 columns: 让我们看看哪些行具有超过201列:

$ awk "{if (NF>201) print NR, NF}" tmp
68 217
580 206
613 390
615 234
657 273
676 610
679 237
720 269
722 238
743 223
762 420

The first coloumn shows the line number, the second number of columns. 第一个列显示行号,第二个列显示。 So your line with 610 columns is line number 676. I aslo printed line 676: 因此,您有610列的行是行号676。我也打印了行676:

676行

so you see it really contains data, no multiple spaces which are filles with zeros. 因此您会看到它确实包含数据,没有多个空格用零填充。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM