[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Strange syntax

From: Jordi Gutiérrez Hermoso
Subject: Re: Strange syntax
Date: Wed, 28 Nov 2012 11:22:37 -0500

On 28 November 2012 06:15, Juan Pablo Carbajal <address@hidden> wrote:
> Now, there is not such a thing as curly braces modifier. The curly
> braces are used to index (i.e. access the elements) of cells, which
> are a type of general container in Octave (like vector from the C++
> STL).

A cell array consists of cells (I think the Mathworks took the name
inspired by cells in spreadsheets) which can contain any data type.
Cell arrays are always at least two dimensional, like every other
Octave type, including structs and strings and ordinary numerical

Unlike a C++ vector, a single cell array can contain different types.
The type that a C++ vector contains is part of the vector's type, so
std::vector<int> and std::vector<char> are different and generally
incompatible types.

> When a cell is indexed with the colon operator ":", it gives all its
> elements.

To be clear, when a cell array is indexed with curly braces and a {},
the cells get "unpacked" into comma-separated lists (cs-lists).
When a cell array is indexed with (), you get a subcell array. Compare

    {1, [1 2; 3 4], "hello}{1:2}


    {1, [1 2; 3 4], "hello}(1:2)

As Juan Pablo explains below, the unpacked cells in cs-lists usually
have semantics equal to syntactically typing out each of the cells

> Assume that foo as defined before calls, in its body, a function bar
> with signature "function bar (x,y)". The call
>      bar (varargin{:})
> is equivalent to
>      bar ("bar", 3)
> To know more about cells read the Octave manual.

I am working on improving the Octave manual to give a better overview
of the basic Octave types.

- Jordi G. H.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]