【问题标题】:how an index value can be used to retrieve the respective name(string)如何使用索引值来检索相应的名称(字符串)
【发布时间】:2017-08-09 13:49:59
【问题描述】:

通过使用 listdlg 可以从列表中选择文件,但它会返回相应的索引作为输出,而不是选择的名称(所选实体的字符串)。如何在输出中获取所选文件的名称??'

例如

[Selection, ok] = listdlg(Name,Value,...);

% selection is nothing but a index of selected entities. 

【问题讨论】:

  • 我已经用一个例子更新了我的帖子。

标签: matlab matlab-guide


【解决方案1】:

对话框中填充了作为ListString 参数值提供的元胞数组。调用listdlg 的结果是该单元数组的索引。

考虑以下代码:

filelist=dir("/home");
S={filelist.name};
[Selection,ok]=listdlg('ListString',S,'SelectionMode','single');
if (ok) filename=cell2mat(S(Selection)) endif

如果选择了项目user1,它应该输出

filename = user1

更新

SelectionModemultiple 时,您可以使用celldisp(S(Selection))。要提取单个项目,请使用S{Selection(i)},其中i 的范围从1 到length(Selection)

filelist=dir("/home");
S={filelist.name};
[Selection,ok]=listdlg('ListString',S,'SelectionMode','multiple');
if (ok) 
  for i=1:length(Selection)
    disp(S{Selection(i)}) 
  end
endif

【讨论】:

    猜你喜欢
    • 2010-12-13
    • 2022-06-22
    • 2018-10-15
    • 2023-01-11
    • 1970-01-01
    • 2023-03-16
    • 2021-08-11
    • 1970-01-01
    • 2017-04-01
    相关资源
    最近更新 更多