MATLAB: fprintf/sprintf to print string + matrix
问题 I wanted to know, if it's possible to print a string followed by a matrix, written in the classic form, for example: 5 5 9 >>your matrix is M = 1 4 2 2 1 3 using fprintf / sprintf . 回答1: If your matrix doesn't have to be on the same line as the text, you can do something as simple as replacing ; with \n in the output of mat2str: A=[1 2 3; 4 5 6; 7 8 9]; intro_str = 'Your matrix is:\n'; sprintf([intro_str strrep(mat2str(A),';','\n ')]) Your matrix is: [1 2 3 4 5 6 7 8 9] If, however, you want