필터 지우기
필터 지우기

Help: Table cannot edit in a programmatic GUI?

조회 수: 3 (최근 30일)
Khanh
Khanh 2014년 11월 3일
댓글: Jan 2017년 1월 5일
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