1:问题引入:
3:例子
当双击(或者回车)jpg,png或者bmp中的一个之后,返回值imgExt即为选中的值。
在某些场合,需要进行用户交互,比如给定一些选项,让用户进行选择,此时,listdlg就是一个不错的选择,比如如下的一个例子:
列出本文件夹下的所有文件,双击时会返回选择的文件的索引。
2:listdlg函数介绍
输入是参数对,输出(当双击或者敲击回车)是列表项的索引
Parameter | Description |
'ListString' | cell array of strings for the list box. |
'SelectionMode' | string; can be 'single' or 'multiple'; defaults to'multiple'. |
'ListSize' | [width height] of listbox in pixels; defaults to [160 300]. |
'InitialValue' |
vector of indices of which items of the list box
are initially selected; defaults to the first item.
|
'Name' | String for the figure's title; defaults to ''. |
'PromptString' |
string matrix or cell array of strings which appears
as text above the list box; defaults to {}.
|
'OKString' | string for the OK button; defaults to 'OK'. |
'CancelString' | string for the Cancel button; defaults to 'Cancel'. |
在进行批量处理的时候,我要选择需要处理的是bmp或者其他类型的图片,此时,最好是先用户进行一次选择,代码如下:
str = {'jpg','png','bmp'};
[s,v] = listdlg('PromptString','Double click to choose the image format.',...
'SelectionMode','single','ListString',str,...
'Name','Select a image format','InitialValue',1,...
'ListSize',[230,100]);
imgExt = str{s};
执行效果如下: