help-octave
[Top][All Lists]
Advanced

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

Re: Multiple input()


From: Joe Koski
Subject: Re: Multiple input()
Date: Fri, 19 Nov 2004 09:50:09 -0700
User-agent: Microsoft-Entourage/11.0.0.040405

Thanks to Paul, Miroslaw and others who suggested solutions to prompting for
several input numbers on one line. Both Paul's and Miroslaw's solutions
work. In the approach Paul suggested, I get the correct results if I change
"strtok()" to "str2num()". I like Paul's solution because it is transparent
to the person who is running the script that the string conversion takes
place. My suggestion would be to add this tip to the help file for input.

Joe

on 11/18/04 11:39 PM, Paul Laub at address@hidden wrote:

> Dear Joe, 
> 
> What about calling input() with the optional second argument of "s"?
> That way, one item, a string, is returned. That string, however, could
> contain multiple values separated by whitespaces or commas or
> whatever. Then you could use Octave's strtok() to parse the individual
> values from that string. By putting strtok() within a loop, you could
> in principle parse out all of an unknown number of values in the
> string. (At least that is how the same named strtok library function
> in C is used.)
> 
> Paul Laub 
> 
> 
> On Thu, 18 Nov 2004 21:10:28 -0700, Joe Koski <address@hidden> wrote:
>> To quote from the February 1997 GNU Octave Manual, p. 127:  "Currently input
>> [meaning the Octave input() function] only returns one value, regardless of
>> the number of values produced by the the evaluation of the expression."
>> Entering "help input" in Octave-2.1.57 gets the same wording.
>> 
>> Have any changes/updates allowed prompting for the reading a specified
>> number of values? Is there a "workaround" that uses scanf(template,"C"), or
>> similar constructs, that allows the number of inputs to vary from run to
>> run?
>> 
>> For a simple data plot display, I would like to ask: "How many columns to
>> plot?: 3". (That I can do.) Then I would enter a varying number of column ID
>> numbers, e.g. 5,10,15. Or, better yet, just count three entries and produce
>> the plots.
>> 
>> Yes, I could do it with a loop with input() asking for one column ID number
>> at a time.
>> 
>> Any ideas? Tricks? Suggestions? Thanks.
>> 
>> Joe
>> 
>> -------------------------------------------------------------
>> 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]