How do I list the combinations of a set in lexicographical order?

December 1, 2012 in Math, Matlab, Octave, Recipes

Suppose we have a set composed of elements. Our goal is to list all the possible ways in which we can choose elements in a lexicographical order. Intuitively speaking, we
…read more

How do I Initialize a Struct Array in Matlab/Octave?

July 9, 2012 in Matlab, Octave

Suppose that you want to create a 2D array whose entries are the structures: The easiest (in my opinion) way to to this is using the syntax: This will initialize
…read more

How do I generate an array from the field of a struct array in Matlab/Octave?

June 3, 2012 in Matlab, Octave, Recipes

Let’s first present the situation. Consider the following code snippet: This code will generate a 100×100 struct array containing the fields uniform and gaussian. Now imagine that you want to
…read more

How do I get a fully qualified path in Matlab/Octave?

May 29, 2012 in Matlab, Octave, Recipes, Shell

You can use this one line function (tested only on Unix like systems): For example, suppose that the current directory is /Users/zuliani/Documents/Temp. Then: octave:1> fullpath(‘.’) ans = /Users/zuliani/Documents/Temp octave:2> fullpath(‘../../Documents/’)
…read more

How do I convert a byte representation of a number into its decimal equivalent and viceversa in Matlab/Octave?

February 21, 2012 in Matlab, Octave, Recipes

Let’s consider the case of a standard single precision number (a float) that is represented by 4 bytes. Suppose we want to find the byte hexadecimal representation of x=3.141592. To
…read more

How do I detect if I am running Octave rather than Matlab?

January 11, 2011 in Octave, Recipes

Just use this snippet: isOctave = exist(‘OCTAVE_VERSION’) ~= 0; If isOctave is true then you are running Octave. See this discussion for more information.