Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.



Re: any way to assign a block of text as variable?
Posted:
Oct 22, 2012 10:53 PM


In article <k64v9s$hcb$1@newscl01ah.mathworks.com>, "P" <pyjunk.nospam@shaw.ca> wrote:
> Hi, > > I am using matlab to generate code. It would be nice if I can copy and paste > the existing header block into a matlab script, assign it to a variable, then > have matlab write it back into the output file. > > ie: the header block looks like > > ######### > # Date ... > # Author ... > # > ######### > > The problem is I can't find a matlab type that would take this multiline > string as a single variable. Ideally, I want to write the entire block of > text into a file like > > fprintf(fid, '%s', magical_variable); > > Am I missing something here? > > > > Thanks,
You can embed eol (endofline) characters in the string with fprintf or sprintf using '\n':
fprintf('line 1\nline 2\n')
Additionally, you might find my verbatim function useful:
<http://www.mathworks.com/matlabcentral/fileexchange/23194>
 Doug Schwarz dmschwarz&ieee,org Make obvious changes to get real email address.



