raw={'p1','p2','p3'}; %points id
column1=[200;250;300]; %distances
column1=num2cell(column1);
cellArray=[raw,column1];
set(handles.uitable1, 'Data', cellArray); %predetermined blank uitable in GUI
%I wanna create blank check box (false and adjustable) for each rows in uitable. When I click on any checkbox in uitable (false to true) belongs to its row, I want to retrieve this row's distance (column 1) for some calculation in editor page.

 채택된 답변

Walter Roberson
Walter Roberson 2014년 4월 22일

0 개 추천

'ColumnFormat', 'logical'
'CellEditCallback', set it to a function handle
If this function is called as a function handle, uitable passes it two arguments. The first argument, source, is the handle of the uitable. The second argument, eventdata, is an event data structure that contains the fields shown in the following table.
So look at the eventdata parameter. It will be a structure, with a field 'Indices' that tell you the row and column the user changed. The PreviousData and NewData fields of the structure can be used to determine whether the user is turning false to true.

댓글 수: 3

sermet
sermet 2014년 4월 22일
편집: sermet 2014년 4월 22일
Walter, I'm afraid I don't understand clearly what you're trying to say (my background is not enough to comprehend it clearly).
Could you explain me again as a rudimentary level what I need to do with codes please. Especially points id and distances' rows number would be changed so I need to write a loop while creating uitable.
raw={'p1'; 'p2'; 'p3'}; %points id %COLUMN not row
column1=[200;250;300]; %distances
column1=num2cell(column1);
checked=false(size(raw,1),1); %is it checked?
cellArray=[raw,column1,checked];
set(handles.uitable1, 'Data', cellArray);
set(handles.uitable1, 'ColumnFormat', {'string', 'numeric', 'logical'});
set(handles.uitable1, 'CellEditCallback', @check_checked);
function check_checked(src, eventdata);
cur_data = get(src, 'Data');
where_changed = eventdata.Indices;
row_changed = where_changed(1);
id_affected = cur_data{row_changed, 1);
dist_affected = cur_data(row_changed, 2);
... now do something with the information ...
end
Robert
Robert 2018년 8월 10일
Thank you for this! One note: shouldn't
'string'
be
'char'
when setting the column format?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Tables에 대해 자세히 알아보기

질문:

2014년 4월 22일

댓글:

2018년 8월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by