Help: Table cannot edit in a programmatic GUI?

3 次查看(过去 30 天)
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.

采纳的回答

Orion
Orion 2014-11-3
编辑:Orion 2014-11-3
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 个评论
Pravin Kokane
Pravin Kokane 2017-1-5
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 2017-1-5
@Pravin Kokane: Please do not attach a new question as a comment to an answer. Open a new thread instead. Thanks.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by