FAQ

From Octave
Revision as of 10:40, 15 November 2011 by Joannac (talk | contribs) (Added link to forums)
Jump to navigation Jump to search

General

Who uses Octave?

Lots of people. It seems that universities use it for research and teaching, companies of all sizes, for development, individuals. This question comes often on Octave mailing lists, see WhoUsesOctave for a few answers

Coding

How do we erase a figure?

closeplot(); 
closefig(number)

How do we vary the line thickness?

  • There's plpot_octave, but the one in debian doesn't work for me.
  • Here's my octave hack for it--- http://gnufans.net/~deego/pub/octave/plot_width.m This one simply draws the line multiple times.
  • You can edit the .eps file manually or using sed and awk.
  • Export the graph as fig file (gset term fig thickness 2). This also allows for easy postediting with xfig and export to formats not supported by gnuplot.
  • The gplot command of octave does not support gnuplot's linewidth parameter Thus you must use the graw() function for sending this option directly to gnuplot, eg.
graw('replot "" notitle with lines lw 4\n');

How do I call an octave function from C++?

  • Here is an untested code snippet for calling rand([9000,1]), modified from a post by HerberFarnsworth? to help-octave on 2003-05-01:
#include <octave/oct.h>
...
ColumnVector NumRands(2);
NumRands(0) = 9000;
NumRands(1) = 1;
octave_value_list f_arg, f_ret;
f_arg(0) = octave_value(NumRands);
f_ret = feval("rand",f_arg,1);
Matrix unis(f_ret(0).matrix_value());

How do I create a full semilog/log grid

gset grid mxtics mytics
gset grid lw 2, lw 0.1
grid("on");

One can use postscript enhancement for proper axis

gset format x "10^{%%L}"

or

gset format y "10^{%%L}" 

How do I change colour/line definition in gnuplot postscript?

Here is a awk script to get a rainbow colour map

#!/bin/awk -f
 
 BEGIN {
   split("0 4 6 7 5 3 1 2 8", rainbow, " ");
   split("7 3 1 0 2 4 6 5 8", invraim, " ");
 }
 
 $1 ~ /\/LT[0-8]/ {
   n = substr($1, 4, 1);
   if (n == 0)
     lt = "{ PL [] 0.9 0.1 0.1 DL } def";
   else if (n == 1)
     lt = "{ PL [4 dl 2 dl] 0.1 .75 0.1 DL } def";
   else if (n == 2)
     lt = "{ PL [2 dl 3 dl] 0.1 0.1 0.9 DL } def";
   else if (n == 3)
     lt = "{ PL [1 dl 1.5 dl] 0.9 0 0.8 DL } def";
   else if (n == 4)
     lt = "{ PL [5 dl 2 dl 1 dl 2 dl] 0.1 0.8 0.8 DL } def";
   else if (n == 5)
     lt = "{ PL [4 dl 3 dl 1 dl 3 dl] 0.9 0.8 0.2 DL } def";
   else if (n == 6)
     lt = "{ PL [2 dl 2 dl 2 dl 4 dl] 0.5 0.3 0.1 DL } def";
   else if (n == 7)
     lt = "{ PL [2 dl 2 dl 2 dl 2 dl 2 dl 4 dl] 1 0.4 0 DL } def";
   else if (n == 8)
     lt = "{ PL [2 dl 2 dl 2 dl 2 dl 2 dl 2 dl 2 dl 4 dl] 0.5 0.5 0.5 DL } def";
   $0 = sprintf("/LT%d %s", rainbow[n+1], lt);
   ##$0 = sprintf("/LT%x %s", invraim[n+1], lt);
   ##$0 = sprintf("/LT%x %s", n, lt);
 }
 
 { print; }

How do I tell if a file exists?

Look at functions like exist, file_in_path.. and the other functions that their descriptions point to.

How do I get sound output in Windows?

See http://www.octave.org/octave-lists/archive/help-octave.2003/msg01567.html for a start.

How do I create a plot without a window popping up (ie, a plot to a file)?

 figure(1, "visible", "off");
 plot(sin(1:100));
 print -deps "/tmp/sin.eps"

One can set that behaviour as default:

 set(0, 'defaultfigurevisible', 'off');

Why does Octave segfault when using "clear all;"?

This is a known problem if you have one of the following packages loaded:

ann
database
ftp 

See http://www.nabble.com/Segmentation-Fault---Clear-all-td21998563.html for a discussion