[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Multiple input()
From: |
Miquel Cabanas |
Subject: |
Re: Multiple input() |
Date: |
Fri, 19 Nov 2004 14:26:35 +0100 |
User-agent: |
Mutt/1.3.28i |
hello,
On Thu, Nov 18, 2004 at 09:10:28PM -0700, Joe Koski wrote:
>
> 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.
>
some time ago I wrote an improved version of the menu() function
to be able to select several options. As you will notice, I used
input() to read several numbers as a string, and then splitted the
string into substrings and converted those back into numbers. The
relevant portion of the code is,
s = input ("pick one or more numbers separated by spaces: ", "s");
## now check that s is a string, split it into substrings,
## convert the substrings to numbers, and then check that
## values are valid
eval (sprintf ("num = str2num (s);"), "num = [];");
if (! any (is_vector (num)) || any (num < 1) || any(num > nopt))
printf ("\nerror: some input invalid or out of range\n\n");
else
num = sort (num);
break;
endif
Hope this helps,
Miquel
--
Miquel E Cabanas ------------------------------------------------------
SeRMN, Universitat Autonoma de Barcelona (address@hidden)
------------------------------------------o-oo--ooo---ooo--oo-o--------
mult_choice.m
Description: Text document