## The module "num2cellstr" of the Mastrave modelling library

**Daniele de Rigo**

#### Copyright and license notice of the function num2cellstr

Copyright © 2007,2008,2009,2010,2011 Daniele de Rigo

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

val_cellstr = num2cellstr(values,format= '%g' )

#### Description

Utility to extend the ability of the function num2str( ... ) to convert
numbers in strings. Instead of concatenating the array of numbers
` values ` into a single string, this utility generate the cell-string

`whose elements are strings each converting the corresponding numeric element of`

**val_cellstr**`. If passed, the input argument`

**values**`allows to customize the conversion.`

**format**

#### Input arguments

valuesVector, matrix or multidimensional-array of real numbers.::real::formatFormat string to customize the conversion from numbers to strings. It must be suitable to be used by the family of C-language derived functions *printf. If omitted, the default value is '%g'.::format_string::

#### Example of usage

% Basic usage num2cellstr( 1 ) num2cellstr( [ 1 pi -1.23 inf nan 0 ] ) num2cellstr( [ 1 pi -1.23 ; inf nan 0 ] ) % Customizing the conversion num2cellstr( [ 1 pi -1.23 inf nan 0 ] , '%d' ) num2cellstr( [ 1 pi -1.23 inf nan 0 ] , '[%g]' ) % Motivating example n = 20 [x,y,z] = mdeal( cumsum( cumsum( randn( n , 3 ) ) ) ); figure( 1 ); hold off; plot( x, y, 'o-' ) text( x, y, num2cellstr( z , ' %.2g' ) ) figure( 2 ); hold off; plot3( x, y, z, '-' ) text( x, y, z, num2cellstr( 1:n ) )

See also: int2ordinal Keywords: conversion, cell-array, number, string Version: 0.4.7

#### 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.