Code covered by the BSD License  

Highlights from
NUM2LAB

Be the first to rate this file! 2 Downloads (last 30 days) File Size: 1.71 KB File ID: #20698
image thumbnail

NUM2LAB

by Marco Cococcioni

 

14 Jul 2008 (Updated 17 Jul 2008)

Converts a numeric vector into a cell vector of strings.

| Watch this File

File Information
Description

This function converts a numeric vector into a cell vector of strings. Each element of the cell contains the string conversion of the corresponding entry in the numeric vector, prefixed and postfixed by strings provided by the user. The format for numeric to string conversion can also be specified.
Useful for creating legend labels or tick labels.

MATLAB release MATLAB 7.4 (R2007a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (2)
15 Jul 2008 Jos x@y.z

Better to use the oneliner:
    
% data
V = [1 2 3 4.5 6 pi] ;
prestr = 'Text before '
poststr = ' .. and after '
formstr = '%.2f' ;
    
% engine
C = cellstr(num2str(V(:),[prestr formstr poststr]))
    

21 Jul 2008 Marco Cococcioni

Thank you Jos! I have updated the submission using your suggestion!

Please login to add a comment or rating.
Updates
17 Jul 2008

Core function replaced with the more efficient version based on the use of cellstr and num2str (thanks to Jos).

Tag Activity for this File
Tag Applied By Date/Time
conversion Marco Cococcioni 22 Oct 2008 10:10:11
labels Marco Cococcioni 22 Oct 2008 10:10:11
generation Marco Cococcioni 22 Oct 2008 10:10:11
num2lab Marco Cococcioni 22 Oct 2008 10:10:11
numeric Marco Cococcioni 22 Oct 2008 10:10:11
vector Marco Cococcioni 22 Oct 2008 10:10:11

Contact us at files@mathworks.com