Octave can be built with many configurations so programs may end up running
in a machine without features they need. Developers should never expect an
Octave installation to have all features. And programs should identify if
the required features are available.

This is a list of possible tests to check for features:

## support for 64 bit indexingsizemax()>intmax("int32")## built with support for javausejava("jvm")## Image IO with support for tif filesany(cellfun(@(x)ismember("tif",x),{imformats.ext}))## Image IO with support for png filesany(cellfun(@(x)ismember("png",x),{imformats.ext}))

It's not recommended to use this if the only purpose is to then fail
in the absence of the package. In such case, simply try to load the package
and Octave will already give a error message that is informative enough.

There is only purpose to check this, if there is something different to
do if a package is missing. The same is true for catching an error from
pkg load. If you only catch an error to then throw it again
then you might as well not catch it in the first place.

## This contraption doesn't add anything. If 'pkg load' fails, it## will already give an error message to the user.trypkgloadfoo;catcherror("failed to load foo: %s",lasterr());end_try_catch## Again, doesn't add anything. The failure of 'pkg load' is enoughif(isempty(pkg("list","foo")))error("program: package foo is not installed");endif

Beware that an installed package is not always a guarantee that a function
will be available. Some packages may disable functions at build time, or
specific functions may have specific runtime requirements.

Returning all values in a comma separated lists allows you to make anything out of them.
If numbers are expected, create a matrix by enclosing them in square brackets.
But if strings are to be expected, a cell array can also be easily generated with curly brackets

{samples(:).patient}

You are also not limited to return all elements, you may use logical indexing from other fields to get values from the others:

[samples([samples(:).age]>34).tube]## return tube numbers from all samples from patients older than 34[samples(strcmp({samples(:).protein},"CDK2")).tube]## return all tube numbers for protein CDK2

printf and family do not accept cell arrays as values.
However, they keep repeating the template given as long as it has enough arguments to keep going.
As such, the trick is on supplying a cs-list of elements which can be done by using a cell array and index it with {}.

Since values are stored in column-major order, paired values need to be on the same column.
A new row of data can then be added later with

Another option is to use the function csvread. However, this function can't handle non-numerical data.

The probably best option is to use the function csv2cell from the IO package. This function can read mixed-type (numerical and text) .csv files, allows to specify other field separators than a comma and other text protection characters (default: " double quote) and can skip header lines. If you have the IO package installed and loaded, type help csv2cell at the Octave prompt for more info.

Reading XML in octave can be achieved using the java library Apache Xerces.

It seems that the Matlab's xmlread is just a thin wrapper around the Apache Xerces library.
One should note however, that Java functions have the working directory set to the working directory when octave starts and the working directory is not modified by a cd in octave.
Matlab has the same behavior, as Java does not provide a way to change the current working directory (http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4045688).
To avoid any issues, it is thus better to use the absolute path to the XML file.

filename="sample.xml";## These three lines are equivalent to xDoc = xmlread(filename) in Matlabparser=javaObject("org.apache.xerces.parsers.DOMParser");parser.parse(filename);xDoc=parser.getDocument();elem=xDoc.getElementsByTagName("data").item(0);## get first data element data=elem.getFirstChild.getTextContent();## get text from childatt=elem.getAttribute("att");## get attribute named att

A string in Octave is just a character matrix and can easily be converted to numeric form back and forth.
Each character has an associated number (the asci function of the miscellaneous package displays a nicely formatted conversion table).

any(mod(values,2))## true if at least one number in values is evenall(mod(values,2))## true if all numbers in values are oddany(!logical(mod(values,2)))## true if at least one number in values is evenall(!logical(mod(values,2)))## true if all numbers in values are even

Since we are checking for the remainder of a division, the first choice would be to use rem.
However, in the case of negative numbers mod will still return a positive number making it easier for comparisons.
Another alternative is to use bitand (X, 1) or bitget (X, 1) but those are a bit slower.

Note that this solution applies to integers only.
Non-integers such as 0.5 or 4.201 are neither even nor odd.
If the source of the numbers are unknown, such as user input, some sort of checking should be applied for NaN, Inf, or non-integer values.

One sometimes needs to define a family of functions depending on a set of parameters, e.g., f(x,y,z;a,b,c){\displaystyle f(x,y,z;a,b,c)} where x,y,z{\displaystyle x,y,z} denote a the variables on which the function operates and a,b,c{\displaystyle a,b,c} are the parameters used to chose one specific element of the family of functions.

For example, let's say we need to compute the time evolution of the elongation of a spring for different values of the spring constant k{\displaystyle k}

Given a set of points in space we want to calculate the distance between all of them.
Each point is described by its components (xi,yi,…){\displaystyle (x_{i},y_{i},\ldots )}.
Assume that the points are saved in a matrix P with m rows (one for each point) and n columns, one for each component.

The calculation can be implemented using functions like cellfun and avoid the loop over components of the points.
However in most cases we will have more points than components and the improvement, if any, will be minimal.

Another observation is that the matrix Dsq is symmetric and we could store only the lower or upper triangular part.
To use this optimization in a practical way check the help of the functions vech and unvech (this one is in the Forge package general).
Two functions that haven't seen the light yet are sub2ind_tril and ind2sub_tril (currently private functions in the Forge package mechanics) that are useful to index the elements of a vector constructed with the function vech.
Each page (the third index) of the multidimensional array R is an anti-symmetric matrix and we could also save some memory by keeping only one of the triangular submatrices.

Check the Geometry package for many more distance functions (points, lines, polygons, etc.).