The module "get_cell_elem" of the Mastrave modelling library


Daniele de Rigo


Copyright and license notice of the function get_cell_elem



Copyright © 2005,2006,2007,2008,2009,2010 Daniele de Rigo

The file get_cell_elem.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

Function declaration



[obj, answer, errmsg] = get_cell_elem( cell_array  , 
                                       pos         ,
                                       default_obj ,
                                       obj_type    ,
                                       msg         ,
                                       ...         )




Given a cell_array of arbitrary size (for example given the cell array varargin declared inside a function, representing an arbitrary number of input arguments), returns its element at position pos as output obj . If the cell_array has less than pos elements, then returns a default value ( default_obj ) for that element, similary assigning it to obj . Before returning to the caller, checks if obj belongs to the category obj_type by invoking the function

[ answer , errmsg ] = check_is( obj , obj_type , msg , ... )

For more details on obj_type , msg and the optional arguments, see the function check_is. If answer , errmsg are not requested as output variables, in case of check failure an error is thrown whose text being errmsg .

Input arguments



 cell_array               ::cell::
                          cell array whose  pos -th element type is to
                          be checked

 pos                      ::scalar_index::
                          position of the element whose type has to
                          be checked

 default_obj              ::generic::
                          default value of the output argument  obj  when
                           cell_array  has less than  pos  elements

 obj_type                 ::generic|row_string::
                          constraint to be checked. See the help of
                          check_is function for details.

 msg                      ::string::
                          string containing the message to emit in case of
                          check-failure.  It can optionally contain
                          C-language format tags that are replaced by the
                          values specified in subsequent additional arguments.
                          See check_is and fprintf help for more details.

Example of usage



    [obj, answer, errmsg] = get_cell_elem( { 'foo' 1234 } , 1 , 'bar'  , ...
                                           'string' , 'must be a string!' )
    [obj, answer, errmsg] = get_cell_elem( { 'foo' 1234 } , 2 , 'bar'  , ...
                                           'string' , 'must be a string!' )
    [obj, answer, errmsg] = get_cell_elem( { 'foo' 1234 } , 3 , 'bar'  , ...
                                           'string' , 'must be a string!' )

See also:
    cell2sparse, cellstr2index

   cell-array, varargin

Version: 0.2.4




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.

Valid XHTML 1.0 Transitional