简体   繁体   English

用于读取文本文件的 Matlab 脚本与 Octave 不兼容

[英]Matlab script for reading a text file is not compatible with Octave

To import data from a text file I use a script in MATLAB.要从文本文件导入数据,我使用 MATLAB 中的脚本。 I want to run the same script in Octave but then I get an error.我想在 Octave 中运行相同的脚本,但随后出现错误。

An extract of the text file that I want to read looks as follows:我要阅读的文本文件的摘录如下所示:

Rotation angle  Measured distance
-0,342  0,000
-1,440  0,000
-10,422 0,000
-11,574 0,000
-21,060 0,000
-21,528 0,000
-30,402 0,000

The following code is reading the text file:以下代码正在读取文本文件:

filename = 'C:\Users\marci\Desktop\Stackoverflow\S4P1_Logfile_160419_1345.txt';   
delimiter = '\t';
startRow = 3;
formatSpec = '%s%s%[^\n\r]';
fileID = fopen(filename,'r');
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'TextType', 'string', 'HeaderLines' ,startRow-1, 'ReturnOnError', false, 'EndOfLine', '\r\n');
fclose(fileID);

That is the error message that I get in Octave.那是我在 Octave 中收到的错误消息。

error: textscan: unrecognized option 'texttype'
error: called from
    test at line 35 column 11

Does anyone know how to fix this error?有谁知道如何解决这个错误?

texttype is not one of the recognized properties for textscan in Octave, see https://octave.sourceforge.io/octave/function/textscan.html . texttype不是 Octave 中textscan的公认属性之一,请参阅https://octave.sourceforge.io/octave/function/textscan.html

By looking at the MATLAB documentation for textscan , it looks like texttype doesn't do much anyway:通过查看 textscan 的textscan文档,看起来texttype并没有做太多事情:

在此处输入图像描述

I would suggest removing it altogether from the function call.我建议将它从 function 调用中完全删除。 It should just work.它应该可以工作。

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

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