Code covered by the BSD License  

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
cprintf: a pedestrian ND array formatting and display utility

5.0 | 7 ratings Rate this file 14 Downloads (last 30 days) File Size: 62.5 KB File ID: #23840 Version: 1.13
image thumbnail

cprintf: a pedestrian ND array formatting and display utility


us (view profile)


20 Apr 2009 (Updated )

cprintf converts an ND array or ND cell array to a 2D character array and - optionally - a table

| Watch this File

File Information

- converts
  an ND array of
  - real and/or complex full numeric data
  - real and/or complex sparse numeric data
  - logical data
  - char strings
  - structures
  - other objects
  or an ND cell array of any combination of the above
  to a 2D character array
- creates tables
  - the input may be a cell array formatted as a table with
    row/column labels and row/column separators
  - any simple (ND) array can be formatted as a table using
    any combination of
    row/column labels and row/column separators

many options allow to format each aspect of the input and output

to better organize a project using CPRINTF
- options may be entered by an option structure
- options may be read from any ASCII file
- options may be saved in an executable m-file, which
  returns an option structure

saving output
- the output may be saved in an ASCII file
- optionally, a file template may be used to insert the
  result at a marked position
- tokens in a file template may be replaced by user defined
  strings during runtime

CPRINTF may be a useful front end engine to create input for a spreadsheet program

> help cprintf
and the accompanying published M-file for more information and examples

> cphelp
to open the published M-file in a ML browser window

> cpdoc
to run the examples used in the published M-file

MATLAB release MATLAB 7.7 (R2008b)
Other requirements optimized for r2009a
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (15)
04 May 2011 Felipe G. Nievinski

Would you consider replacing this block (~ l.1050):

v=par.s2f('@(x) x'); % WARNING only
v(10); % ERROR to catch
catch %#ok

for this one:

[msg_str_old, msg_id_old] = lastwarn('', '');
par.s2f('@(x) x'); % WARNING only
[msg_str, msg_id] = lastwarn(msg_str_old, msg_id_old);
if strcmp(msg_id, 'MATLAB:str2func:invalidFunctionName')

I'm asking because sometimes I have to run code using dbstop if caught error.

02 Aug 2010 us

us (view profile)

hi cyberfrog

unfortunately, this is not possible...
you have to create the complete CELL in your loop and append it afterwards using the -fa option...
note: you could use the -Lc option to create the column labels at write-time...


Comment only
26 Jan 2010 Yoni

Yoni (view profile)

So I looked at the part you mentioned and it doesn’t do what I want. I’m trying to avoid xlswrite because I have a mix of strings and numbers. Is there any way to make cprintf do the actual file output but without any spaces for padding?

Comment only
23 Jan 2010 Yoni

Yoni (view profile)

I may well have missed that part. It’s a pretty long file and searching it for “tab” or “space” brings up a lot of hits. I’ll peruse that part. Thanks!

Comment only
23 Jan 2010 us

us (view profile)

hi yonatan

did you look at the last section in CPDOC(?)...
--- input to xlswrite

it shows how to use the content of
to create (for instance) excel data


Comment only
23 Jan 2010 Yoni

Yoni (view profile)

This function is great for quickly and easily printing a cell array to a text file without worrying too much about format strings. But I can’t figure out how to prevent it from doing any padding with spaces. I’d like to output to a strictly tab-delimited file. I’ll probably be reading said file into excel or SPSS, so I don’t need the spaces for alignment, but I can’t figure out any way to leave them out entirely. (..., 'ntab', 1) isn’t doing it. Am I missing something, or is that functionality absent.


Comment only
23 Jul 2009 qooroo

qooroo (view profile)

one of the most useful and definitely *the* best well made/structured/documented entry in the FEX

20 Jul 2009 qooroo

qooroo (view profile)

13 Jul 2009 Shaun

Shaun (view profile)

I quick question. If I create a column of numbers to reference the rows in my table, I would like to associate those numbers with a hyperlink. While I can perform this operation, the spacing/formatting of the column labels becomes quite ugly. Is there a simple solution?

By the way, I really enjoy using your function. It's great!

Comment only
21 Jun 2009 ANSHUL

ANSHUL (view profile)

24 May 2009 Hal 9000  
21 May 2009 us

us (view profile)

1) you show the input to FPRINTF; how do you call CPRINTF?
2) the error message indicates that some input values are not defined(?)
can you clarify?

Comment only
21 May 2009 Gordon Ariho

I have tried cprintf on both release 7.5 and 7.8 but i get 'undefined function or variable...' I have tried to use fprintf but it disorganises the matrix

fprintf('Distance \t Path_loss \t Rx_Power \t SNR \n');fprintf('%f \t %f \t %f \t %f \n',K)

Comment only
23 Apr 2009 Y Mehta  
21 Apr 2009 Shaun

Shaun (view profile)

21 Apr 2009 1.2

added more explanatory text in the published M-file and corrected some annoying typos; no change in functionality; version tag: 21-Apr-2009 20:51:35

22 Apr 2009 1.3

formatting changes in the HTML
more help in the processing section of the HTML
the [-db] output now contains more information
change in the conversion engine for speed-up if an array only contains numeric data
version tag 22-Apr-2009 18:18:43

13 May 2009 1.4

extensive changes in handling of ND arrays and ND cell arrays of mixed content including optional page index display; version tag 13-May-2009 12:40:03

15 May 2009 1.5

full support for ND structures; small change in page indexing engine; version tag 16-May-2009 02:57:29

18 May 2009 1.6

speedup for ND logical arrays; version tag 18-May-2009 14:35:01

21 May 2009 1.7

improved handling of ND arrays and ND cell arrays of other objects; version tag 21-May-2009 15:20:31

21 May 2009 1.8

added options to create/append results to ASCII files including use of template files; version tag 21-May-2009 21:58:49

22 May 2009 1.9

the other object conversion now uses a more versatile built-in engine; version tag 22-May-2009 12:27:24

01 Jun 2009 1.12

options now may be read from/saved to files and entered by option structures; more help on macros; version tag 01-Jun-2009 20:57:29

11 Jun 2009 1.13

user request: added an option to change default TAB/SPACE replacement behavior in CELLs; version tag 11-Jun-2009 08:58:55

Contact us