inp.m
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
Cite As
Miroslav Balda (2024). inp.m (https://www.mathworks.com/matlabcentral/fileexchange/9033-inp-m), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
Tags
Acknowledgements
Inspired: SINIDE - Parameter identification of a sine-wave from a measured signal
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.