Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: sscanf
Date: Mon, 27 Oct 2008 15:02:02 +0000 (UTC)
Organization: Pierburg GmbH
Lines: 23
Message-ID: <ge4l5a$la9$1@fred.mathworks.com>
References: <ge4gmp$r05$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1225119722 21833 172.30.248.37 (27 Oct 2008 15:02:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 27 Oct 2008 15:02:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 872224
Xref: news.mathworks.com comp.soft-sys.matlab:497447


"doe john" <johnnydoe1515@gmail.com> wrote in message <ge4gmp$r05$1@fred.mathworks.com>...
> HI, I have a chain of characters string + number delimited by  semi '; ' as following
> 
> line ='name.rrr; ; 78;7;6;;string;;0'
> 
> first I replacethe ';' by a tab
> line = regexprep(line,';','\t')
> Then, I try to use 
> [A, count, errmsg, nextindex]=sscanf(line, '%s, %d,%d,%d,%d,%s,%s,%s,%d') 
> 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. 

sscanf reads the first string, but then expects a comma as it appears after the first %s in your format string. 

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 "Output Characteristics: Both Numeric and Character Values Read" paragraph in the sscanf doc).


Matlab's textscan is much better here:

line ='name.rrr; ; 78;7;6;;string;;0'
A = textscan(line,'%s %d %d %d %d %s %s %s %d','Delimiter',';');


(it should definitely be listed in the "See also" section of the sscanf help page, too)