<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/238234</link>
    <title>MATLAB Central Newsreader - sscanf</title>
    <description>Feed for thread: sscanf</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>Mon, 27 Oct 2008 13:46:01 -0400</pubDate>
      <title>sscanf</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/238234#607503</link>
      <author>doe john</author>
      <description>HI, I have a chain of characters string + number delimited by  semi '; ' as following&lt;br&gt;
&lt;br&gt;
line ='name.rrr; ; 78;7;6;;string;;0'&lt;br&gt;
&lt;br&gt;
first I replacethe ';' by a tab&lt;br&gt;
line = regexprep(line,';','\t')&lt;br&gt;
Then, I try to use &lt;br&gt;
[A, count, errmsg, nextindex]=sscanf(line, '%s, %d,%d,%d,%d,%s,%s,%s,%d') &lt;br&gt;
but I was not able to retrieve those different data. I get the name.rr in A but in error , I get matching failure in format. I don't understand why it doesnt retrieve other data. &lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;Thanks&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;Joe</description>
    </item>
    <item>
      <pubDate>Mon, 27 Oct 2008 15:00:28 -0400</pubDate>
      <title>Re: sscanf</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/238234#607525</link>
      <author>Walter Roberson</author>
      <description>doe john wrote:&lt;br&gt;
&amp;gt; HI, I have a chain of characters string + number delimited by  semi '; ' as following&lt;br&gt;
&amp;nbsp;&lt;br&gt;
&amp;gt; line ='name.rrr; ; 78;7;6;;string;;0'&lt;br&gt;
&lt;br&gt;
&amp;gt; first I replacethe ';' by a tab&lt;br&gt;
&amp;gt; line = regexprep(line,';','\t')&lt;br&gt;
&amp;gt; Then, I try to use &lt;br&gt;
&amp;gt; [A, count, errmsg, nextindex]=sscanf(line, '%s, %d,%d,%d,%d,%s,%s,%s,%d') &lt;br&gt;
&amp;gt; but I was not able to retrieve those different data. I get the name.rr in A but in error ,&lt;br&gt;
&amp;gt;  I get matching failure in format. I don't understand why it doesnt retrieve other data. &lt;br&gt;
&lt;br&gt;
When you put a comma in your sscanf format, then sscanf will look for a literal comma in&lt;br&gt;
your input. Do not put any delimiter between the various format elements. A lot of people&lt;br&gt;
put spaces, but it is best not to even put those. For example, you might use&lt;br&gt;
&lt;br&gt;
'%s%d%d%d%d%s%s%s%d'&lt;br&gt;
&lt;br&gt;
However, you are still going to have problems with the empty fields. Both of the&lt;br&gt;
format elements you have specified, %s and %d, skip -all- leading whitespace, where&lt;br&gt;
&quot;whitespace&quot; is tab or space (or vertical tab, or carriage return, or newline.)&lt;br&gt;
The leading %s format will read the 'name.rrr', but the %d after that will skip over&lt;br&gt;
to the 78, the second %d will get the 7, the third %d will get the 6, then the&lt;br&gt;
fourth %d will skip over and try reading from 'string', which is going to fail.&lt;br&gt;
And if it did somehow work (e.g., the string happened to be all digits), then&lt;br&gt;
the %s that follows in the format string would skip over the whitespace to the 0&lt;br&gt;
leaving you with a %s and %d not satisfied.&lt;br&gt;
&lt;br&gt;
I would suggest that for your purposes, it would probably be easier to split&lt;br&gt;
at the semi-colon and parse the individual parts.</description>
    </item>
    <item>
      <pubDate>Mon, 27 Oct 2008 15:02:02 -0400</pubDate>
      <title>Re: sscanf</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/238234#607526</link>
      <author>Andres </author>
      <description>&quot;doe john&quot; &amp;lt;johnnydoe1515@gmail.com&amp;gt; wrote in message &amp;lt;ge4gmp$r05$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; HI, I have a chain of characters string + number delimited by  semi '; ' as following&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; line ='name.rrr; ; 78;7;6;;string;;0'&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; first I replacethe ';' by a tab&lt;br&gt;
&amp;gt; line = regexprep(line,';','\t')&lt;br&gt;
&amp;gt; Then, I try to use &lt;br&gt;
&amp;gt; [A, count, errmsg, nextindex]=sscanf(line, '%s, %d,%d,%d,%d,%s,%s,%s,%d') &lt;br&gt;
&amp;gt; but I was not able to retrieve those different data. I get the name.rr in A but in error , I get matching failure in format. I don't understand why it doesnt retrieve other data. &lt;br&gt;
&lt;br&gt;
sscanf reads the first string, but then expects a comma as it appears after the first %s in your format string. &lt;br&gt;
&lt;br&gt;
Besides, reading mixed strings and numbers is not very comfortable with sscanf since it will put everything together into a single numeric matrix (read the &quot;Output Characteristics: Both Numeric and Character Values Read&quot; paragraph in the sscanf doc).&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Matlab's textscan is much better here:&lt;br&gt;
&lt;br&gt;
line ='name.rrr; ; 78;7;6;;string;;0'&lt;br&gt;
A = textscan(line,'%s %d %d %d %d %s %s %s %d','Delimiter',';');&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
(it should definitely be listed in the &quot;See also&quot; section of the sscanf help page, too)</description>
    </item>
  </channel>
</rss>

