Octave 使用日志

Updated at: March 11, 2017

install package


>> error: 'LINPROG' undefined near line 38 column 12
error: called from
  ~/Documents/写论文的计算数据/DEA-BSC_1set.m at line38 column 11

>> pkg list
no packages installed.
>> pkg load optim
error: package optim is not installed
error: called from
    load_packages at line 53 column 11
    pkg at line 422 column 7
>> pwd
ans = /home/ghluo
>> pkg install ~/Downloads/optim-1.5.2.tar.gz
warning: creating installation directory /home/ghluo/octave
warning: called from
    install at line 30 column 5
    pkg at line 405 column 9
error: the following dependencies were unsatisfied:
    optim needs struct >= 1.0.12

-auto The package manager will automatically load the installed package when starting Octave. This overrides any setting within the package.

>> pkg install ~/Downloads/struct-1.0.14.tar.gz -auto
For information about changes from previous versions of the struct package, run 'news struct'.
>> pkg install ~/Downloads/optim-1.5.2.tar.gz -auto
For information about changes from previous versions of the optim package, run 'news optim'.

linspace & logspace

  • logspace, 对数分割
      Return a row vector with n elements logarithmically spaced from 10^a to 10^b.
      If n is unspecified it defaults to 50.
      If b is equal to pi, the points are between 10^a and pi, not 10^a and 10^pi, 
      in order to be compatible with the corresponding MATLAB function.
      Also for compatibility with MATLAB, return the second argument b if fewer than two values are requested.
      logspace(-2, 2, 5)
      ans =
         1.0000e-02   1.0000e-01   1.0000e+00   1.0000e+01   1.0000e+02
  • linspace, 线性分割
      Return a row vector with n linearly spaced elements between base and limit.
      If the number of elements is greater than one, then the endpoints base and limit are always included in the range. 
      If base is greater than limit, the elements are stored in decreasing order. 
      If the number of points is not specified, a value of 100 is used.
      The linspace function returns a row vector when both base and limit are scalars. 
      If one, or both, inputs are vectors, then linspace transforms them to column vectors 
      and returns a matrix where each row is an independent sequence between base(row_n), limit(row_n).
      For compatibility with MATLAB, return the second argument (limit) if fewer than two values are requested.
      ans =
         0   1   2   3   4   5

Crash after plot interaction

GNU Octave - Bugs: bug #48482, Crash after plot interaction

Someone said: I can confirm that on Ubuntu Xenial (16.04) upgrading to the latest stable Mesa as per http://www.omgubuntu.co.uk/2016/12/stable-mesa-drivers-ubuntu-ppa (ppa:paulo-miguel-dias/pkppa) the crash is resolved.

After I add this ppa(mesa drivers), and upgrade ubuntu-desktop(sudo apt dist-upgrade), Octave works!!. However, there are 3 new problems:

  1. DisplayLink(Dell Docker) doesn’t work any more. No HDMI input for my two extend screens.
  2. How to fix “The system is running in low-graphics mode” error?
  3. Each time when I login, “system detect errors: xorg…”

How to resolve this problem? Loged in ubuntu-desktop-使用日志

datatype conversion

compatible with Matlab


char Convert to character array
num2str Convert numbers to character array
str2double Convert string to double precision value
str2num Convert character array to numeric array
native2unicode Convert numeric bytes to Unicode character representation

concatenate string



s = strcat(s1,...,sN)


s = strcat(s1,...,sN) horizontally concatenates s1,…,sN. Each input argument can be a character array, a cell array of character vectors, or a string array.

  • If any input is a string array, then the result is a string array.
  • If any input is a cell array, and none are string arrays, then the result is a cell array of character vectors.
  • If all inputs are character arrays, then the result is a character array.

For character array inputs, strcat removes trailing ASCII white-space characters: space, tab, vertical tab, newline, carriage return, and form feed. For cell and string array inputs, strcat does not remove trailing white space.



str = strjoin(C)
str = strjoin(C,delimiter)


  • str = strjoin(C) constructs a single piece of text, str, by linking each element in the array, C, with a single space. C can be a cell array of character vectors or a string array.
  • str = strjoin(C,delimiter) constructs str by linking each element of C with the elements in delimiter.

dynamic matrix

>> A = [];
>> A(1,1) = 1;
>> A(2,1) = 1;
>> A(3,1) = 1;
>> A
>> A =



Create an inline function from the character string STR

>> xtimesexp = inline('x*e')
xtimesexp = f(x) = x*e
>> xtimesexp(5)
ans =  13.5914091422952