Module: Octave::Io
- Defined in:
- lib/octave/io.rb,
lib/octave/polyfit.rb
Constant Summary collapse
- OCTAVE_EXE =
'/usr/bin/env octave -q'
Class Method Summary collapse
-
.command(command_string) ⇒ Object
Octave::Io.command(command_string).
-
.polyfit(x, y, n) ⇒ Object
Octave::Io.polyfit(x, y, n).
Class Method Details
.command(command_string) ⇒ Object
Octave::Io.command(command_string)
send a command to Octave in a pipe and return the results. The results are returned as arrays of float values
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/octave/io.rb', line 14 def command(command_string) res = [] decorated_command_string = "echo \"#{command_string}\" | #{OCTAVE_EXE}" IO.popen(decorated_command_string) do |octave_result| out = octave_result.readlines.map { |l| l.chomp } out.each { |line| res << line.to_f if line.match?(/\s*\d+/) } end res end |
.polyfit(x, y, n) ⇒ Object
Octave::Io.polyfit(x, y, n)
get the coefficients of an n-degree polynomial using octave
‘s polyfit
function
13 14 15 16 |
# File 'lib/octave/polyfit.rb', line 13 def polyfit(x, y, n) command_string = "a = polyfit(#{x}, #{y}, #{n}); a'" ::Octave::Io.command(command_string) end |