Use uitable with static text?
1 次查看(过去 30 天)
显示 更早的评论
Please help. I am preparing a GUI (guide) and have a couple of questions:
1) from a pushbutton I want to import the filename of all .txt files in the directory and place the filename in a uitable as static text.
2) in the uitable I want only one row to start with, but add one new empty row at the end to add new info manually. This should be a uigetfile, potentially through a pushbutton, to allow the user to include other .txt files located outside the dir. Every time the last row is filled it should automatically add a new empty row to the uitable. And finally:
3) import all the .txt (mixed data and char) files specified in the uitable potentially via a loop to generate mixed data arrays.
I know this is a lot but hopefully someone can help me. I am open to better suggestions if any. THANKS a lot.
0 个评论
回答(1 个)
Walter Roberson
2017-8-29
uitable cannot have static text exactly. You can set a cell to a string and set the associated ColumnEditable to false, but that affects all entries in the column which might be a problem as you also want users to be able add new entries.
You can can set the celledit callback to set the contents back if they are changed.
You will need one of those callback functions to detect that the user has entered something so that you would know to add a new row.
3 个评论
Walter Roberson
2017-8-30
编辑:Walter Roberson
2017-8-30
function push1_callback(hObject, event, handles)
dname = uigetdir('', 'Select a directory');
if ~ischar(dname); return; end %user canceled
dinfo = dir( fullfile( dname, '*.txt') );
filenames = fullfile( dname, {dinfo.name} );
set( handles.uitable1, 'Data', filenames(:) );
function push2_callback(hObject, event, handles)
[filename, dname] = uigetfile('*.txt', 'Select additional files');
if ~ischar(filename); return; end %user canceled
filename = fullfile(dname, filename);
existing_data = get( handles.uitable1, 'data');
existing_data{end+1,1} = filename;
set( handles.uitable1, 'Data', existing_data );
function push3_callback(hObject, event, handles)
existing_data = get( handles.uitable1, 'data');
mask = cellfun(@isempty, existing_data);
existing_data(mask, :) = [];
numfile = size(existing_data, 1);
filecontents = cell(numfile, 1);
for K = 1 : numfile
this_file = existing_data{K, 1};
filecontents{K} = import_one_file( this_file );
end
handles.filecontents = filecontents;
guidata(hObject, handles); %save the contents in the handles structure
... for appropriate import_one_file routine that you will need to write
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!