<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265236</link>
    <title>MATLAB Central Newsreader - Issues Writing to File</title>
    <description>Feed for thread: Issues Writing to File</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Sat, 07 Nov 2009 13:28:01 -0500</pubDate>
      <title>Issues Writing to File</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265236#692877</link>
      <author>Ashley </author>
      <description>I'm having trouble writing to a file using fprintf.  The issues is I need to write lines like:&lt;br&gt;
&lt;br&gt;
fprintf('        name='C:/Documents and Settings/ecslogon/Desktop/ME726_Project/Marco Test/Test_Job-3.odb'\n');&lt;br&gt;
&lt;br&gt;
This means that I need to print &quot; ' &quot; to the file without ending the fprintf statement.  How is this done?&lt;br&gt;
&lt;br&gt;
The second issue is I need to write &quot; ( &quot; and &quot; ) &quot; to the file without ending the fprintf (see example below) or causing Matlab to give me an inblance error.  How is this done? &lt;br&gt;
&lt;br&gt;
fprintf('        INVARIANT, 'Max. Principal'), )), ))\n\n');&lt;br&gt;
&lt;br&gt;
Thank you for your time,&lt;br&gt;
Ashley</description>
    </item>
    <item>
      <pubDate>Sat, 07 Nov 2009 13:58:45 -0500</pubDate>
      <title>Re: Issues Writing to File</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265236#692879</link>
      <author>dpb</author>
      <description>Ashley wrote:&lt;br&gt;
&amp;gt; I'm having trouble writing to a file using fprintf. The issues is I&lt;br&gt;
&amp;gt; need to write lines like:&lt;br&gt;
&amp;gt; fprintf('     name='C:/Documents and ...&lt;br&gt;
&lt;br&gt;
...&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;gt;&amp;gt; sprintf('%s','It''s an embedded ''.')&lt;br&gt;
ans =&lt;br&gt;
It's an embedded '.&lt;br&gt;
&amp;nbsp;&amp;gt;&amp;gt;&lt;br&gt;
&lt;br&gt;
Double up on the apostrophes is one way; another is to insert the &lt;br&gt;
numeric values w/ strrep in an existing string at a desired location or &lt;br&gt;
use strcat or , to build the string.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;gt;&amp;gt; pstrphe = double('''')&lt;br&gt;
pstrphe =&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;39&lt;br&gt;
&amp;nbsp;&amp;gt;&amp;gt;  char(pstrphe)&lt;br&gt;
ans =&lt;br&gt;
'&lt;br&gt;
&amp;nbsp;&amp;gt;&amp;gt; s = ['That', char(pstrphe), 's a string.']&lt;br&gt;
s =&lt;br&gt;
That's a string.&lt;br&gt;
&amp;nbsp;&amp;gt;&amp;gt;&lt;br&gt;
&lt;br&gt;
for example.  repmat() sometimes comes in handy for repeated strings as &lt;br&gt;
well.&lt;br&gt;
&lt;br&gt;
help strfun&lt;br&gt;
&lt;br&gt;
to see the full ML repertoire from which to choose...&lt;br&gt;
&lt;br&gt;
BTW, I assume you did get the max stress data read correctly?&lt;br&gt;
&lt;br&gt;
--</description>
    </item>
    <item>
      <pubDate>Sat, 07 Nov 2009 14:08:01 -0500</pubDate>
      <title>Re: Issues Writing to File</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265236#692883</link>
      <author>Ashley </author>
      <description>dpb &amp;lt;none@non.net&amp;gt; wrote in message &amp;lt;hd3uer$cnn$1@news.eternal-september.org&amp;gt;...&lt;br&gt;
&amp;gt; Ashley wrote:&lt;br&gt;
&amp;gt; &amp;gt; I'm having trouble writing to a file using fprintf. The issues is I&lt;br&gt;
&amp;gt; &amp;gt; need to write lines like:&lt;br&gt;
&amp;gt; &amp;gt; fprintf('     name='C:/Documents and ...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; ...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;  &amp;gt;&amp;gt; sprintf('%s','It''s an embedded ''.')&lt;br&gt;
&amp;gt; ans =&lt;br&gt;
&amp;gt; It's an embedded '.&lt;br&gt;
&amp;gt;  &amp;gt;&amp;gt;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Double up on the apostrophes is one way; another is to insert the &lt;br&gt;
&amp;gt; numeric values w/ strrep in an existing string at a desired location or &lt;br&gt;
&amp;gt; use strcat or , to build the string.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;  &amp;gt;&amp;gt; pstrphe = double('''')&lt;br&gt;
&amp;gt; pstrphe =&lt;br&gt;
&amp;gt;      39&lt;br&gt;
&amp;gt;  &amp;gt;&amp;gt;  char(pstrphe)&lt;br&gt;
&amp;gt; ans =&lt;br&gt;
&amp;gt; '&lt;br&gt;
&amp;gt;  &amp;gt;&amp;gt; s = ['That', char(pstrphe), 's a string.']&lt;br&gt;
&amp;gt; s =&lt;br&gt;
&amp;gt; That's a string.&lt;br&gt;
&amp;gt;  &amp;gt;&amp;gt;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; for example.  repmat() sometimes comes in handy for repeated strings as &lt;br&gt;
&amp;gt; well.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; help strfun&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; to see the full ML repertoire from which to choose...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; BTW, I assume you did get the max stress data read correctly?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; --&lt;br&gt;
&lt;br&gt;
Yes thank you I did get the max stress read correctly although I used a different method.  Although what you suggested worked I was worried that it would fail if the max stress was for some reason written on a different line.  A friend helped me write the following:&lt;br&gt;
&lt;br&gt;
fid=fopen(filename,'r');&lt;br&gt;
eofstat=0;&lt;br&gt;
&lt;br&gt;
while (eofstat == 0);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;tline = fgetl(fid);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;[a,b] = size(tline);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if b &amp;gt;= 9 &amp; tline(1:9) == '  Maximum';&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;find = 1;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;values = sscanf(tline, '%s %f' );&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;max = values(8);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;break&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;eofstat = feof(fid);&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
fclose(fid);&lt;br&gt;
&lt;br&gt;
Which works very well and doesn't care which line the max stress is writtne on. Thanks again for all your help.&lt;br&gt;
Ashley</description>
    </item>
    <item>
      <pubDate>Sat, 07 Nov 2009 14:24:21 -0500</pubDate>
      <title>Re: Issues Writing to File</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265236#692890</link>
      <author>dpb</author>
      <description>Ashley wrote:&lt;br&gt;
...&lt;br&gt;
&amp;gt; Yes thank you I did get the max stress read correctly although I used&lt;br&gt;
&amp;gt; a different method. Although what you suggested worked I was&lt;br&gt;
&amp;gt; worried that it would fail if the max stress was for some reason&lt;br&gt;
&amp;gt; written on a different line. ...&lt;br&gt;
&lt;br&gt;
No, that was the whole point of the 'Maximum' in the format string in &lt;br&gt;
textread()--that _requires_ that the string be matched followed by the &lt;br&gt;
value so that your certain that it isn't a differing one that will be read.&lt;br&gt;
&lt;br&gt;
Otherwise, if there were a malformed file using '%s %f' would possibly &lt;br&gt;
allow you to transparently get a value that wasn't the maximum w/o &lt;br&gt;
knowing about it.&lt;br&gt;
&lt;br&gt;
But, it's your data, suit yourself...&lt;br&gt;
&lt;br&gt;
--</description>
    </item>
    <item>
      <pubDate>Sat, 07 Nov 2009 15:09:53 -0500</pubDate>
      <title>Re: Issues Writing to File</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265236#692895</link>
      <author>dpb</author>
      <description>dpb wrote:&lt;br&gt;
&amp;gt; Ashley wrote:&lt;br&gt;
&amp;gt; ...&lt;br&gt;
&amp;gt;&amp;gt; Yes thank you I did get the max stress read correctly although I used&lt;br&gt;
&amp;gt;&amp;gt; a different method. Although what you suggested worked I was&lt;br&gt;
&amp;gt;&amp;gt; worried that it would fail if the max stress was for some reason&lt;br&gt;
&amp;gt;&amp;gt; written on a different line. ...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; No, that was the whole point of the 'Maximum' in the format string in &lt;br&gt;
&amp;gt; textread()--that _requires_ that the string be matched followed by the &lt;br&gt;
&amp;gt; value so that your certain that it isn't a differing one that will be read.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Otherwise, if there were a malformed file using '%s %f' would possibly &lt;br&gt;
&amp;gt; allow you to transparently get a value that wasn't the maximum w/o &lt;br&gt;
&amp;gt; knowing about it.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; But, it's your data, suit yourself...&lt;br&gt;
&lt;br&gt;
OH...dawned on me what your concern was -- it, indeed, somebody were to &lt;br&gt;
change the format of number of lines/file ahead of the value not a fubar &lt;br&gt;
in the file itself--yes, the textread() solution does require the format &lt;br&gt;
be consistent whereas as long as they don't introduce a maximum &lt;br&gt;
something else before of your intended one the posted solution will &lt;br&gt;
handle it.&lt;br&gt;
&lt;br&gt;
--</description>
    </item>
  </channel>
</rss>

