简体   繁体   English

MATLAB与GNU Octave Textscan差异

[英]MATLAB vs. GNU Octave Textscan disparity

I wish to read some data from a .dat file without saving the file first. 我希望从.dat文件中读取一些数据,而不先保存文件。 In order to do so, my code looks as follows: 为此,我的代码如下所示:

urlsearch= 'http://minorplanetcenter.net/db_search/show_object?utf8=&object_id=2005+PM';
url= 'http://minorplanetcenter.net/tmp/2005_PM.dat';

urlmidstep=urlread(urlsearch);
urldata=urlread(url);

received= textscan(urldata , '%5s %7s %1s %1s %1s %17s %12s %12s %9s %6s %6s %3s ' ,'delimiter', '', 'whitespace', '');
data_received = received{:}

urlmidstep 's function is just to do a "search", in order to be able to create the temporary .dat file. urlmidstep的功能只是进行“搜索”,以便能够创建临时的.dat文件。 This data is then stored in urldata , which is a long char array. 然后,此数据存储在urldata ,它是一个长字符数组。 When I then use textscan in MATLAB, I get 12 columns as desired, which are stored in a cell array data_received . 然后,当我在MATLAB中使用textscan时,将根据需要获得12列,这些列存储在单元数组data_received

However, in Octave I get various warning messages: warning: strread: field width '%5s' (fmt spec # 1) extends beyond actual word limit (for various field widths). 但是,在Octave中,我收到各种警告消息: warning: strread: field width '%5s' (fmt spec # 1) extends beyond actual word limit (对于各种字段宽度)。 My question is, why is my result different in Octave and how could I fix this? 我的问题是,为什么我的结果在八度音阶中不同,我该如何解决? Shouldn't Octave behave the same as MATLAB, as in theory any differences should be dealt with as bugs? Octave的行为不应该与MATLAB一样吗,因为从理论上讲,任何差异都应作为bug处理?

Surely specifying the width of the strings and leaving both the delimiter and whitespace input arguments empty should tell the function to only deal with width of string, allowing spaces to be a valid characters. 确保指定字符串的宽度并将定界符和空格输入参数都保留为空应该告诉该函数仅处理字符串的宽度,从而使空格成为有效字符。

Any help would be much appreciated. 任何帮助将非常感激。

I thinhk textscan works differently in MATLAB and Octave. 我的Thinhk textscan在MATLAB和Octave中的工作方式有所不同。 To illustrate let's simplify the example. 为了说明,让我们简化示例。 The code: 编码:

test_line = 'K05P00M  C2003 01 28.38344309 37 57.87 +11 05 14.9                n~1HzV645';
test = textscan(test_line,'%5s','delimiter','');
test{:}

will would yield the following in MATLAB: 在MATLAB中将产生以下内容:

>> test{:}

ans = 

    'K05P0'
    '0M  C'
    '2003 '
    '01 28'
    '.3834'
    '4309 '
    '37 57'
    '.87 +'
    '11 05'
    '14.9 '
    'n~1Hz'
    'V645'

whereas in Octave, you get: 而在Octave中,您将获得:

>> test{:}
ans =
{
  [1,1] = K05P0
  [2,1] = C2003
  [3,1] = 01
  [4,1] = 28.38
  [5,1] = 37
  [6,1] = 57.87
  [7,1] = +11
  [8,1] = 05
  [9,1] = 14.9
  [10,1] = n~1Hz
}

So it looks like Octave jumps to the next word and discards any remaining character in the current word, whereas MATLAB treats the whole string as one continuous word. 因此,看起来Octave会跳到下一个单词,并丢弃当前单词中的所有剩余字符,而MATLAB将整个字符串视为一个连续的单词。

Why that is and which is one is correct, I do not know, but hopefully it'll point you in the right direction for understanding what is going on. 我不知道为什么会这样,而哪个才是正确的,但希望它会为您指出正确的方向。 You can try adding the delimiter to see how it affects the results. 您可以尝试添加delimiter以查看它如何影响结果。

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

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