inputgui

版本 1.0.0.0 (2.4 KB) 作者: Toby Driscoll
A simple, flexible, and overridable graphical replacement for INPUT.
3.5K 次下载
更新时间 2003/5/19

查看许可证

INPUTGUI allows a user to set function parameters through an input dialog window. It's meant to be a replacement for INPUT. Among its virtues is that the dialog popup can be overriden either by accepting defaults or by assigning (some of the) values through the function call. It's also meant to be very easy to use.

The standard calling sequence is

value = INPUTGUI(name,default,prompt)

Arguments name, default, and prompt are identically sized cell arrays of strings. They define the names, default values, and interactive prompt strings for the parameters, which are assumed to be numerical.

On exit, each parameter value will be assigned *in the caller's workspace*.

INPUTGUI(name,default,prompt,isstring) adds a logical vector that designates corresponding parameters as strings.

INPUTGUI(...,action) modifies the behavior:
'default': Default values are returned for all parameters (no dialog is opened).
struct: Each parameter will have the default value unless overridden by a field of the same name (no dialog).
[]: Standard behavior.

For example, suppose you wrote the function

function y = inputtest(varargin)
name = { 'Moe', 'Larry', 'Curly' };
default = { '1/pi', '[-1 0 1]', 'silly' };
prompt = { 'Value of Moe', 'Value of Larry', 'Value of Curly' };
isstring = logical( [0 0 1] );
vals = inputgui(name,default,prompt,isstring,varargin{:})
whos Moe Larry Curly

Then we get
>> inputtest % Brings up a dialog. Press OK and...
vals =

[ 0.3183]
[1x3 double]
'silly'

Name Size Bytes Class
Curly 1x5 10 char array
Larry 1x3 24 double array
Moe 1x1 8 double array

>> s.Larry = 16; inputtest(s) % No dialog appears...
vals =

[0.3183]
[ 16]
'silly'

Name Size Bytes Class
Curly 1x5 10 char array
Larry 1x1 8 double array
Moe 1x1 8 double array

The return argument "value" will be a cell array of the assigned values, as strings. You can assign this to a persistent variable and use it on the next call as the default.

引用格式

Toby Driscoll (2024). inputgui (https://www.mathworks.com/matlabcentral/fileexchange/3413-inputgui), MATLAB Central File Exchange. 检索时间: .

MATLAB 版本兼容性
创建方式 R13
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
版本 已发布 发行说明
1.0.0.0

Bug in the original version for some inputs. Also a slight change in output.