The module "mat2layers" of the Mastrave modelling library

 

Daniele de Rigo

 


Copyright and license notice of the function mat2layers

 

 

Copyright © 2006,2009,2011,2012 Daniele de Rigo

The file mat2layers.m is part of Mastrave.

Mastrave is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Mastrave is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Mastrave. If not, see http://www.gnu.org/licenses/.

Function declaration

 

 

layer_array = mat2layers( matrix                     , 
                          valuemap = @sortable2index )

Description

 

 

Module for transforming a matrix matrix into a three-dimensional array of boolean layers. The matrix values are mapped into corresponding indices by means of the optional input argument valuemap . If valuemap is not passed, the function @sortable2index is used instead. Each layer has the same size of the original matrix . The elements of the i-th layer are true where the corresponding elements of matrix are mapped into the index i.

Input arguments

 

 


 matrix            ::matrix,!sparse::
                   Numeric, charachter or cell-array matrix (whose number
                   of dimensions cannot exceed 2).

 valuemap          ::function_handle::
                   Handle to a custom function for mapping the elements
                   of  matrix  into corresponding indices. The function
                   is expected to accept as input argument a 
                   ::matrix,!sparse:: and to return a matrix of positive
                   integer indices.
                   If omitted, the default value is @sortable2index.


Example of usage

 

 


   % Basic usage:
   M1  = [1 3 2;2 1 1]
   M2  = m1*10 -15
   LM1 = mat2layers( M1 )
   LM2 = mat2layers( M2 )
   assert( isequal( LM1, LM2 ) )
   rev = @(L)sum( 1-cumsum( L, 3 ), 3)+1
   assert( isequal( M1, rev( LM1 )       ) )
   assert( isequal( M2, rev( LM1 )*10-15 ) )

   % Passing as input a cell-array of strings
   C1  = {'foo' 'bar' '' 'foo' 'foo' 'bar'}
   C2  = {'foo' 'bar' '';'foo' 'foo' 'bar'}
   LC1 = mat2layers( C1 )
   LC2 = mat2layers( C2 )

   % Passing a custom valuemap function
   LM3 = mat2layers( M1, @(x)(x>=2)+1   )
   LM4 = mat2layers( M1, @(x)mod(x,2)+1 )


See also:
   mat2multi, multi2mat, mdeal



Keywords:
   multidimensional-array, data-transformation, matrix, boolean



Version: 0.8.1

Support

 

 

The Mastrave modelling library is committed to provide reusable and general - but also robust and scalable - modules for research modellers dealing with computational science.  You can help the Mastrave project by providing feedbacks on unexpected behaviours of this module.  Despite all efforts, all of us - either developers or users - (should) know that errors are unavoidable.  However, the free software paradigm successfully highlights that scientific knowledge freedom also implies an impressive opportunity for collectively evolve the tools and ideas upon which our daily work is based.  Reporting a problem that you found using Mastrave may help the developer team to find a possible bug.  Please, be aware that Mastrave is entirely based on voluntary efforts: in order for your help to be as effective as possible, please read carefully the section on reporting problems.  Thank you for your collaboration.

Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Daniele de Rigo

This page is licensed under a Creative Commons Attribution-NoDerivs 3.0 Italy License.

This document is also part of the book:
de Rigo, D. (2012). Semantic Array Programming with Mastrave - Introduction to Semantic Computational Modelling. http://mastrave.org/doc/MTV-1.012-1


Valid XHTML 1.0 Transitional