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!