Effacer les filtres
Effacer les filtres

Help: Table cannot edit in a programmatic GUI?

3 vues (au cours des 30 derniers jours)
Khanh
Khanh le 3 Nov 2014
Commenté : Jan le 5 Jan 2017
Hi everybody,
Could someone tell me what's wrong with my code? I created a figure with a table in GUIDE and converted it to programmatic by Fig2m (by Thomas Montagnon). Then when I run the figure, the table was shown but cannot edit although I set it editable in GUIDE.
The command window showed 'Warning: Table data is not editable at this location.'
The code:
% --- FIGURE -------------------------------------
handles.figure1 = figure( ...
'Tag', 'figure1', ...
'Units', 'characters', ...
'Position', [102.8 24.2307692307692 114 33], ...
'Name', 'untitled1', ...
'MenuBar', 'none', ...
'NumberTitle', 'off', ...
'Color', [0.941 0.941 0.941]);
% --- UITABLE -------------------------------------
handles.uitable1 = uitable( ...
'Parent', handles.figure1, ...
'Tag', 'uitable1', ...
'UserData', zeros(1,0), ...
'Units', 'characters', ...
'Position', [12.2 8 36.8 21], ...
'BackgroundColor', [1 1 1;0.961 0.961 0.961], ...
'ColumnEditable', [true,true], ...
'ColumnFormat', {'char' 'char' }, ...
'ColumnName', {'1','2'}, ...
'ColumnWidth', {'auto','auto'}, ...
'RowName', {'1','2','3','4'});
Thank you.

Réponse acceptée

Orion
Orion le 3 Nov 2014
Modifié(e) : Orion le 3 Nov 2014
Hi,
You need to initialize the type the Data parameter. by default, Matlab consider it is a double. But you want to put strings in your table. So just specify an cell with empty string when creating the uitable.
% --- FIGURE -------------------------------------
handles.figure1 = figure( ...
'Tag', 'figure1', ...
'Units', 'characters', ...
'Position', [102.8 24.2307692307692 114 33], ...
'Name', 'untitled1', ...
'MenuBar', 'none', ...
'NumberTitle', 'off', ...
'Color', [0.941 0.941 0.941]);
% --- UITABLE -------------------------------------
% Initialize empty string for components of the Data
Data=cell(4,2);
for i = 1:numel(Data)
Data{i} = '';
end
handles.uitable1 = uitable( ...
'Parent', handles.figure1, ...
'Tag', 'uitable1', ...
'UserData', zeros(1,0), ...
'Units', 'characters', ...
'Position', [12.2 8 36.8 21], ...
'BackgroundColor', [1 1 1;0.961 0.961 0.961], ...
'ColumnEditable', [true,true], ...
'ColumnFormat', {'char','char' }, ...
'ColumnName', {'1','2'}, ...
'ColumnWidth', {'auto','auto'}, ...
'RowName', {'1','2','3','4'},...
'Data',Data); % add the "string" Data
  3 commentaires
Pravin Kokane
Pravin Kokane le 5 Jan 2017
In my UI I want to make user defined rows (the no user will enter in EditText) with 3 columns, Then the data entered I want to do mathematical calculations on it. With above answer I was able to get table but don't know how to get the user entered data. The above answer was useful to me but only half part. Suggest some advise. Thanks in advance.
Jan
Jan le 5 Jan 2017
@Pravin Kokane: Please do not attach a new question as a comment to an answer. Open a new thread instead. Thanks.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by