MATLAB: I have problem with displaying a matrix with command fprintf

fprintflong string

Hi Everybody
I have problem with displaying a matrix with command fprintf, a string line is too long and I like to divided in to two parts but I couldn't do it. Is there any one have an idea how to separate it it into parts. I copied the code, the problem is with third line.
Thanks in advance
z=rand(4,15);
fprintf(1,'+---------+---------+----------+-----------+-----------+---------+---------+----------+-----------+-----------+---------+---------+----------+-----------+-----------+\n')
fprintf(1,'| %7.4f |%8.3f |%10.2f|%11.2f| %9.4f |%8.4f |%8.3f |%10.2f|%11.2f| %9.4f |%8.3f |%8.3f |%10.3f|%11.3f| %9.4f |\n+---------+---------+----------+-----------+-----------+---------+---------+----------+-----------+-----------+---------+---------+----------+-----------+-----------+\n',z')

Best Answer

row_divider = '+---------+---------+----------+-----------+-----------+---------+---------+----------+-----------+-----------+---------+---------+----------+-----------+-----------+';
row_fmt = '| %7.4f |%8.3f |%10.2f|%11.2f| %9.4f |%8.4f |%8.3f |%10.2f|%11.2f| %9.4f |%8.3f |%8.3f |%10.3f|%11.3f| %9.4f |';
z=rand(4,15);
zc = mat2cell(z, ones(1,size(z,1)), size(z,2));
zaug = [zc(:), repmat({row_divider},size(z,1),1)] .';
fprintf(1, '%s\n', row_divider);
fprintf(1, [row_fmt '\n%s\n'], zaug{:});
Or more simply,
row_divider = '+---------+---------+----------+-----------+-----------+---------+---------+----------+-----------+-----------+---------+---------+----------+-----------+-----------+';
z=rand(4,15);
fprintf(1,'%s\n', row_divider)
fprintf(1, ['| %7.4f |%8.3f |%10.2f|%11.2f| %9.4f |%8.4f |%8.3f |%10.2f|%11.2f| %9.4f |%8.3f |%8.3f |%10.3f|%11.3f| %9.4f |\n' row_divider '\n'],z')
The first version shows how you can mix data strings with rows of values: create a cell with the data and {:} expand the mixed-type cell.