help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sscanf "inconsistency" ?


From: Henry F. Mollet
Subject: Re: sscanf "inconsistency" ?
Date: Fri, 22 Oct 2004 08:43:48 -0700
User-agent: Microsoft-Entourage/10.1.1.2418

Peter,
Great explanation. I'm beginning to at least understand the problem.
Henry

on 10/21/04 2:05 PM, Peter Jensen at address@hidden wrote:

> Henry,
> 
> Sorry I did not elaborate sufficiently. The problem is that the
> result from sscanf is "ThisisOK" which is not  the same as
> a = ["this" ; "is" ; "OK"] i.e a column vector. As the vector
> returned from sscanf  is a row vector, it is immediately concatenated
> to the string "ThisisOK". It is therefore impossible to
> extract the three  "tokens" namely "this"; "is" and "OK".
> 
> I don't think octave has any other way of extracting "tokens"
> from a string. "split" is a poor substitute as it require an exact match
> of the "separator", whereas sscanf  interprets one or more
> occurrences of "white space" as a separator.
> 
> I think it is a bug that sscanf returns a row vector (when %s is used)
> and not a column vector as suggested by the documentation. This
> also makes the function less usable.
> 
> Any comments ?.
> 
> Peter
> 
> Henry F. Mollet wrote:
> 
>> I'm getting something slightly different. Not sure if it helps.
>> Henry
>> 
>> octave:37> text    = "This is OK" ;
>> octave:38> numbers = "1 2 3 4 5" ;
>> octave:39> [return_string,length] = sscanf(text,"%s") ;
>> octave:40> length
>> length = 3
>> octave:41> return_string
>> return_string = ThisisOK
>> 
>> octave:43> [return_number,length] = sscanf(numbers,"%d") ;
>> octave:44> length
>> length = 5
>> octave:45> return_number
>> return_number =
>> 
>>  1
>>  2
>>  3
>>  4
>>  5
>> 
>> 
>> on 10/20/04 2:09 PM, Peter Jensen at address@hidden wrote:
>> 
>>  
>> 
>>> Hi,
>>> 
>>> I am new to octave. Writing some small test programs
>>> I found the following "inconsistency" in the sscanf
>>> function. When numbers are extracted a column
>>> array  is returned, however if strings are extracted
>>> a row array is returned.  Please note that the number of
>>> fields identified ( written to length) is correct in both cases.
>>> 
>>> Have I misunderstood something, or is sscanf
>>> behaving is an inconsistent manner ?.
>>> 
>>> Peter
>>> -----------------------------------------------------------
>>> 
>>> text    = "This is OK" ;
>>> numbers = "1 2 3 4 5" ;
>>> 
>>> text
>>> [return_string,length] = sscanf(text,"%s") ;
>>> length
>>> return_string
>>> a = ["this" ; "is" ; "OK"]
>>> 
>>> numbers
>>> [return_number,length] = sscanf(numbers,"%d") ;
>>> length
>>> return_number
>>> 
>>> a  = [ 6 ; 7 ; 8 ; 9 ]
>>> 
>>> 
>>> 
>>> 
>>> -------------------------------------------------------------
>>> Octave is freely available under the terms of the GNU GPL.
>>> 
>>> Octave's home on the web:  http://www.octave.org
>>> How to fund new projects:  http://www.octave.org/funding.html
>>> Subscription information:  http://www.octave.org/archive.html
>>> -------------------------------------------------------------
>>> 
>>>    
>>> 
>> 
>> 
>> 
>> -------------------------------------------------------------
>> Octave is freely available under the terms of the GNU GPL.
>> 
>> Octave's home on the web:  http://www.octave.org
>> How to fund new projects:  http://www.octave.org/funding.html
>> Subscription information:  http://www.octave.org/archive.html
>> -------------------------------------------------------------
>> 
>> 
>>  
>> 
> 
> 
> 
> 
> -------------------------------------------------------------
> Octave is freely available under the terms of the GNU GPL.
> 
> Octave's home on the web:  http://www.octave.org
> How to fund new projects:  http://www.octave.org/funding.html
> Subscription information:  http://www.octave.org/archive.html
> -------------------------------------------------------------
> 



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]