David Parks
David Parks

Reputation: 32081

How do I add options to octave functions?

I'm trying to use this function in octave:

[A,B,C,D,E] = textread(f, '%s %d %d %d %d', "headerlines", "1")

This version works fine:

[A,B,C,D,E] = textread(f, '%s %d %d %d %d')

The documentation is somewhat ambiguous on how exactly I should format options such as "headerlines".

The result I get when I try adding in the "headerlines" option:

octave:14> [A,B,C,D,E] = textread(f, '%s %d %d %d %d', "headerlines", 1)
error: textread: A(I): index out of bounds; value 1 out of bound 0
error: called from:
error:   C:\MyProgramFiles\octave\Octave3.6.4_gcc4.6.2_20130408\Octave3.6.4_gcc4.6.2\share\octave\3.6.4\m\io\textread.m    at line 75, column 3

Upvotes: 0

Views: 154

Answers (1)

Telvas
Telvas

Reputation: 158

  1. You have outdated version of Octave. You just encountered a bug fixed over two years ago: http://savannah.gnu.org/bugs/?35824, http://hg.savannah.gnu.org/hgweb/octave/rev/df5488e46dca.
  2. Workaround for this bug if you need "headerlines" prop is to give textread some additional prop (it behaves as intended when "headerlines" IS NOT the only one prop used). For example you can tell it to use endline as endline marker :) (that's default behaviour anyway): [a b c d e] = textread(f, '%s %d %d %d %d', 'headerlines', 1, "endofline", "\r\n") (on Linux you probably want to use '\n' instead of "\r\n").

Upvotes: 1

Related Questions