Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


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

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,374
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$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 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:

<http://www.mathworks.com/matlabcentral/fileexchange/23194>

--
Doug Schwarz
dmschwarz&ieee,org
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]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.