Borrar filtros
Borrar filtros

Use uitable with static text?

1 visualización (últimos 30 días)
Birch
Birch el 29 de Ag. de 2017
Comentada: JB el 30 de Ag. de 2017
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.

Respuestas (1)

Walter Roberson
Walter Roberson el 29 de Ag. de 2017
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 comentarios
Walter Roberson
Walter Roberson el 30 de Ag. de 2017
Editada: Walter Roberson el 30 de Ag. de 2017
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
JB
JB el 30 de Ag. de 2017
AWESOME Walter, thanks a lot.

Iniciar sesión para comentar.

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by