Be the first to rate this file! 139 downloads (last 30 days) File Size: 2.31 KB File ID: #9033

inp.m

by Miroslav Balda

 

15 Nov 2005 (Updated 12 Jan 2009)

Code covered by BSD License  

The function inp.m serves for keyboard input supported by default value

Download Now | Watch this File

File Information
Description

The function implements keyboard input supported by a default value. A user may either accept the default value or enter a new one. Controlled input of data from the keyboard is advantageous for debugging, making protocols via function diary, parametric studies when changing parameters depending on a result of the current iteration, branching run of a program under user wishes, etc, all without debugging.

Forms of a call:
~~~~~~~~~~~~~~~~
  inp % display help
  data = inp; % similar to input('input')
  data = inp(prompt); % similar to input(prompt)
  data = inp(prompt,deflt);
  data = inp(prompt,deflt,form);
  data = inp(prompt,deflt,form,nsp);
% prompt = string of characters
% input with a default value of input data
% form = format of the screen output; default '%9.4f'; format is persistent until new value is given
% nsp = number of leading spaces before prompt on screen; nsp = 10 is persistent until a new value is given
% data = either deflt value if accepted by ENTER, or a new input value

Examples:
~~~~~~~~~
  p = inp('pressure [MPa]',7.5); % if no new value is given, p=7.5
  if strcmp(inp('Continue','yes'),'yes') % for user's on-line decission
      % True branch
  else
      % False branch
  end
  A = eval(inp('A','[B,x]')); % A = [B,x] if no new input
  cx = inp('cxconst',1+i*pi); % gives cx = 1+3.14159i, if accepted

MATLAB release MATLAB 7.3 (R2006b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (2)
13 Jan 2009 Jos (10584)

What is wrong with:
a = input('Give value?') ;
if isempty(a),
  a = defaultvalue ;
end

13 Jan 2009 Miroslav Balda

Your solution is much simpler than that of mine, however, an operator doesn't know in advance, what he (she) is accepting as default.

Please login to add a comment or rating.
Updates
16 Nov 2005

Improving description

12 Jan 2009

Implemented better displaying of comples numbers. Improved description.

Tag Activity for this File
Tag Applied By Date/Time
keyboard Miroslav Balda 22 Oct 2008 08:06:14
input Miroslav Balda 22 Oct 2008 08:06:14
utilities Miroslav Balda 22 Oct 2008 08:06:14
default Miroslav Balda 22 Oct 2008 08:06:14
input Brian 16 Sep 2009 12:45:29
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com