MATLAB: Printmat function for unknown number of rows

Example:
M= rand(5)
printmat(M, 'My Matrix', 'ROW1 ROW2 ROW3 ROW4 ROW5', 'FOO BAR BAZ BUZZ FUZZ' )
but suppose I don't know how many rows I will have (it depends on the user input) what can I do in this situation?
Thank's.

Best Answer

You can build your headers using SPRINTF; for example:
>> M = rand(6) ;
>> vheader = sprintf('ROW%d ', 1:size(M,1))
vheader =
ROW1 ROW2 ROW3 ROW4 ROW5 ROW6
(you might want to STRTRIM the output to get rid of the last white space)