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.
0 个评论
采纳的回答
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
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
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 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!