The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: any way to assign a block of text as variable?
Replies: 2   Last Post: Oct 22, 2012 11:19 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Doug Schwarz

Posts: 1,412
Registered: 12/7/04
Re: any way to assign a block of text as variable?
Posted: Oct 22, 2012 10:53 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

In article <k64v9s$hcb$>,
"P" <> 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 multi-line
> 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 (end-of-line) characters in the string with fprintf or
sprintf using '\n':

fprintf('line 1\nline 2\n')

Additionally, you might find my verbatim function useful:


Doug Schwarz
Make obvious changes to get real email address.

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.