Home > atmlab > handy > input_vector.m

input_vector

PURPOSE ^

INPUT_VECTOR Prompts for user input of vector type.

SYNOPSIS ^

function v = input_vector(s,sorted,min_length)

DESCRIPTION ^

 INPUT_VECTOR   Prompts for user input of vector type.

    Works as INPUT but accepts only input that is a numeric vector.

    The optional arguments can be used to set constraints for allowed
    vectors.
     
 FORMAT   v = input_vector( s [, sorted, min_length ] )

 OUT      v            User input.
 IN       s            String describing the selection
 OPT      sorted       Allow only sorted vectors. 
                       Default is 0 (not sorted).
          min_length   Require a minimum length ofg vector.
                       Default is 1.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

input_vector.m

SOURCE CODE ^

0001 % INPUT_VECTOR   Prompts for user input of vector type.
0002 %
0003 %    Works as INPUT but accepts only input that is a numeric vector.
0004 %
0005 %    The optional arguments can be used to set constraints for allowed
0006 %    vectors.
0007 %
0008 % FORMAT   v = input_vector( s [, sorted, min_length ] )
0009 %
0010 % OUT      v            User input.
0011 % IN       s            String describing the selection
0012 % OPT      sorted       Allow only sorted vectors.
0013 %                       Default is 0 (not sorted).
0014 %          min_length   Require a minimum length ofg vector.
0015 %                       Default is 1.
0016 
0017 % HISTORY: 2003-03-07  Created by Patrick Eriksson
0018 
0019 
0020 function v = input_vector(s,sorted,min_length)
0021 
0022 
0023 if nargin < 2
0024   sorted = 0;
0025 end
0026 
0027 if nargin < 3
0028   min_length = 1;
0029 end
0030 
0031 
0032 
0033 while 1
0034 
0035   v = input( [s,' (give vector as [1,2]): '] );
0036 
0037   if isvector( v )  &  length( v ) >= min_length
0038     if ~sorted  |  ( sorted  &  issorted( v ) )
0039       return
0040     end
0041   end
0042 
0043   fprintf('Incorrect selection. Please try again:\n');
0044 
0045 end

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005