在Matlab

时间:2016-10-29 18:56:34

标签: matlab textbox dynamically-generated

我使用GUIde允许用户从他/她的硬盘驱动器中选择文件,将其加载到列表中,并将加载文件的名称和内容填充到文本框中。

到目前为止,我很擅长将文件加载到列表中。我真的找到了一种方法来根据加载的文件数创建适当数量的文本框。以下是我的剧本:

function pushbutton1_Callback(hObject, eventdata, handles)

% Get file file names from loading directory/folder
filename= uigetfile('*.dat', 'Multiselect','on');

% Show all profi files names in the listbox
set(handles.listbox1,'String',filename);

% Reset selection for all loaded files
for k = 1:length(filename)
set(handles.listbox1,'Value',k);

empty_panel = get(handles.uipanel2,'Tag');
number = length(filename);
for jj = 1:number
    textEl(jj) = uicontrol('Parent', empty_panel, 'Style', ... 
                'text','test','Position', [0 (jj-1)*30, 100, 20]);
end

我之前创建了一个面板(uipanel2),一个按钮(按钮1)和一个列表框(listbox1)。我收到以下错误消息:

 Error using uicontrol
 Invalid convenience arg handle

 Error in plot_profi_V2>pushbutton1_Callback (line 124)
     textEl(jj) = uicontrol('Parent', empty_panel, 'Style', ...
                'text','test');%'Position', [0 (i-1)*30, 100, 20]);

1 个答案:

答案 0 :(得分:0)

两天后我发现了这个问题,下面是脚本供将来参考:

function pushbutton1_Callback(hObject, eventdata, handles)

% Get file file names from loading directory/folder
filename= uigetfile('*.dat', 'Multiselect','on');

% Show all profi files names in the listbox
set(handles.listbox1,'String',filename);

% Reset selection for all loaded files
for k = 1:length(filename)
set(handles.listbox1,'Value',k);

empty_panel = get(handles.uipanel2,'Tag');
number = length(filename);
for jj = 1:number
    textEl(jj)= uicontrol(handles.uipanel2,'Style','text','String',filename{jj}, ...
                     'Units','normalized','Position',[jj/10-0.1 0.9 0.1 0.1]);
end