matlab-0.2.0.0: Matlab bindings and interface

Safe HaskellNone
LanguageHaskell2010

Foreign.Matlab.Array

Contents

Description

Array access, including cell arrays and structures.

Functions here are primarily thin wrappers to the underlying Matlab functions, and the same memory-management semantics hold. In particular, created arrays must be freed, copyMXArray and freeMXArray are deep operations, other set operations do not make copies.

Synopsis

Array manipulation

anyMXArray :: MXArray a -> MAnyArray Source

(Un)cast an array to a generic type.

type MNullArray = MXArray MNull Source

A NULL (empty) array

castMNull :: MAnyArray -> MIO (Maybe MNullArray) Source

Safely cast a generic array to a NULL array, or return Nothing if the array is not NULL

mxArrayClass :: MXArray a -> IO MXClass Source

Return the representation of the type of the elements of an array

mxArraySize :: MXArray a -> MIO MSize Source

Get the size (dimensions) of an array

mxArraySetSize :: MXArray a -> MSize -> IO () Source

Set dimension array and number of dimensions

freeMXArray :: MXArray a -> MIO () Source

Destroy an array and all of its contents.

copyMXArray :: MXArray a -> MIO (MXArray a) Source

Make a deep copy of an array

mIndexOffset :: MXArray a -> MIndex -> MIO Int Source

Convert an array subscript into an offset

Array element access

class MXArrayComponent a where Source

The class of standardly typeable array elements

Minimal complete definition

createMXArray, mxArrayGetOffset, mxArraySetOffset

Methods

createMXArray :: MSize -> MIO (MXArray a) Source

Create an array and initialize all its data elements to some default value, usually 0 or []

isMXScalar :: MXArray a -> MIO Bool Source

Determine if an array is singleton. Equivalent to

 liftM (all (1 ==)) . mxArraySize

mxArrayGetOffset :: MXArray a -> Int -> MIO a Source

mxArraySetOffset :: MXArray a -> Int -> a -> MIO () Source

mxArrayGetOffsetList :: MXArray a -> Int -> Int -> MIO [a] Source

mxArraySetOffsetList :: MXArray a -> Int -> [a] -> MIO () Source

mxScalarGet :: MXArray a -> MIO a Source

Get the value of the first data element in an array or, more specifically, the value that the array will be interpreted as in scalar context

createMXScalar :: a -> MIO (MXArray a) Source

Create a singleton (scalar) array having the specified value

createColVector :: [a] -> MIO (MXArray a) Source

Create a column vector from the given list.

createRowVector :: [a] -> MIO (MXArray a) Source

Create a row vector from the given list.

castMXArray :: forall a. MXArrayComponent a => MAnyArray -> MIO (Maybe (MXArray a)) Source

Safely cast a generic array to a type, or return Nothing if the array does not have the proper type

array element access

mxArrayGet :: MXArrayComponent a => MXArray a -> MIndex -> MIO a Source

Get the value of the specified array element. Does not check bounds.

mxArraySet :: MXArrayComponent a => MXArray a -> MIndex -> a -> MIO () Source

Set an element in an array to the specified value. Does not check bounds.

array list access

mxArrayGetList :: MXArrayComponent a => MXArray a -> MIndex -> Int -> MIO [a] Source

mxArrayGetList a i n gets the sequential list of n items from array a starting at index i. Does not check bounds.

mxArraySetList :: MXArrayComponent a => MXArray a -> MIndex -> [a] -> MIO () Source

mxArraySetList a i l sets the sequential items in array a starting at index i to l. Does not check bounds.

mxArrayGetAll :: MXArrayComponent a => MXArray a -> IO [a] Source

Get a flat list of all elements in the array.

mxArraySetAll :: MXArrayComponent a => MXArray a -> [a] -> IO () Source

Set a flat list of all elements in the array.

Struct access

Structs in Matlab are always arrays, and so can be accessed using most array accessors. |However, the modification functions such as mxArraySet are not implemented because they could disrupt field data in the entire struct array, and so some specialized functions are necessary.

type MStructArray = MXArray MStruct Source

A (array of) structs

createStruct :: MSize -> [String] -> MIO MStructArray Source

Create an N-Dimensional structure array having the specified fields; initialize all values to MNullArray

mStructFields :: MStructArray -> MIO [String] Source

Get the names of the fields

mStructGet :: MStructArray -> MIndex -> String -> MIO MAnyArray Source

Return the contents of the named field for the given element. Returns MNullArray on no such field or if the field itself is NULL

mStructSet :: MStructArray -> MIndex -> String -> MXArray a -> MIO () Source

Sets the contents of the named field for the given element. The input is stored in the array -- no copy is made.

mStructSetFields :: MStructArray -> MIndex -> [MXArray a] -> MIO () Source

Set the fields of a struct index to the given value list. The list corresponds to the field list and must match in size.

mStructAddField :: MStructArray -> String -> MIO () Source

Add a field to a structure array.

mStructRemoveField :: MStructArray -> String -> MIO () Source

Remove a field from a structure array. Does nothing if no such field exists.

Object access

Some structs are also validated (blessed) user objects.

mObjectGetClass :: MStructArray -> IO (Maybe String) Source

Determine if a struct array is a user defined object, and return its class name, if any.

mObjectSetClass :: MStructArray -> String -> IO () Source

Set classname of an unvalidated object array. It is illegal to call this function on a previously validated object array.