MATLAB: Shouldn’t fprintf(s) work for any string s

fprintfMATLABstringsstruct

Hi,
I have a structure array that I want to write to a file. I initially used evalc to do this, but found that Rody Oldenhuis's toString function gave a more informative string. It turns out, however, that I am not able to write the resulting string to a file (or to stdout) with fprintf. The following:
s = toString(myStruct);
fprintf(s)
returns gibberish, even though s is a character array as it should be. I thought fprintf worked for all strings. What am I missing?

Best Answer

fprintf works for strings, but interprets escape characters. Compare:
fprintf('hello, this is a \n backslash');
fprintf('%s', 'hello, this is a \n backslash');
Similar problems occur for %. So better use the '%s' format specifier to display strings.
[EDITED after your comment] I assume "multi-line-string" means a CHAR matrix. A short example would have revealed this immediately. Then:
CStr = cellstr(Str);
fprintf('%s\n', CStr{:});
Please care for adding a helpful example to reduce the time we waste with guessing.