Code covered by the BSD License  

Highlights from
STRPAD String Pad for Matlab

Be the first to rate this file! 8 Downloads (last 30 days) File Size: 2.07 KB File ID: #36766 Version: 1.0
image thumbnail

STRPAD String Pad for Matlab


Gavin (view profile)


Simple function for padding strings with any number of char either at the start or the end

| Watch this File

File Information

This has probably been created by other users, it can also be done easily with printf, but it is not core Matlab (that I know of). Since I use it as is in some of my other libraries so I was asked to add it here.

__ strpad __

A simple function for padding out strings with a single char.
I wrote for a serial driver which required fixed string sizes

__ Author __
Gavin Paul
12th April 2012
Update: 18th May 2012 (added the missing strpad.m file)

__ Files __



__ Instructions __
- type "help strpad" into matlab command line

----------- OUTPUT FROM HELP -----------

STRPAD pads a string with any number of char either at the start or the
  % To pad the string ABC with zeros ('0') at the front to make it 8
  % characters long ('i.e. 00000ABC')
  % To pad the string Hello with zeros ('Q') at the end to make it 14
  % characters long ('i.e. HelloQQQQQQQQQ')
  % To pad the String 101010 with ones ('1') so that it is 16 characters
  % long (i.e. '1111111111101010'). Note by default
  % Error cases:
  % - Not passing in a string
  % Warning cases:
  % - Not passing in the required number of character
  % -- Default: return the string passed in
  % - Passing in a string which is longer than the character requested
  % -- Default: return the string passed in
  % - Passing in more than 1 padding character
  % -- Default: is to pad with '0's

Required Products MATLAB
MATLAB release MATLAB 7.10 (R2010a)
Other requirements No
Tags for This File   Please login to tag files.
Please login to add a comment or rating.

Contact us