필터 지우기
필터 지우기

Updating UiTable - Table not Updated

조회 수: 17 (최근 30일)
Fatih
Fatih 2023년 2월 13일
답변: Voss 2023년 2월 13일
Hello I created a UiTable and I want to Update as a Gui. I want to have an x table as the values entered, but the table is not updated even when I update all cells. Thanks for the help.
++
clc; clear all; close all;
inputType2 = zeros(12, 2); % Type 2 Input Data, First Column upperlimits....
% second column lower limits of the Type-2....
% Fuzzy Sets
RowNamesInputType2 = {'r' 's' 'a1' 'a2' 'a3' 'a4' 'a5' 'a6' 'm1' 'm2' 'n1' 'n2'}; %Row Names Based on hakraborty et. al ...
% "3.3.2 Defuzzification: using centroid technique"
ColumnNamesInputType2 = {'upper' 'lower'}; %Column Names upper&lower Values
inputType2 = array2table(inputType2);
% Table Creation
inputType2 = renamevars(inputType2,["inputType21","inputType22"],ColumnNamesInputType2);
% Column Name Changes of the Table
inputType2.Properties.RowNames = RowNamesInputType2;
% Row Name Assignment
fig = uifigure;
uit = uitable(fig,'Data',inputType2);
uit.ColumnEditable = [true true];
x = uit.Data;
++
  댓글 수: 4
Voss
Voss 2023년 2월 13일
@Fatih: Are you expecting that, when you edit the uit uitable, e.g., by changing a number in one or more of the cells, the value of the variable inputType2 in the base workspace will automatically be updated?
If that's what you want, that would require some additional code.
If that's not what you want, please describe exactly what you are trying to do.
Fatih
Fatih 2023년 2월 13일
That is exactly what I want. Practically, I want to have a table popped up and want the user to enter data(or change). Afterwards, the table will be updated for further use. Hope it helps.

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

답변 (1개)

Voss
Voss 2023년 2월 13일
In order to have edits to the uitable automatically reflected in the workspace variable inputType2, you can give the uitable a CellEditCallback, which is a function that executes when the user edits a cell of the uitable:
clc; clear all; close all;
inputType2 = zeros(12, 2); % Type 2 Input Data, First Column upperlimits....
% second column lower limits of the Type-2....
% Fuzzy Sets
RowNamesInputType2 = {'r' 's' 'a1' 'a2' 'a3' 'a4' 'a5' 'a6' 'm1' 'm2' 'n1' 'n2'}; %Row Names Based on hakraborty et. al ...
% "3.3.2 Defuzzification: using centroid technique"
ColumnNamesInputType2 = {'upper' 'lower'}; %Column Names upper&lower Values
inputType2 = array2table(inputType2);
% Table Creation
inputType2 = renamevars(inputType2,["inputType21","inputType22"],ColumnNamesInputType2);
% Column Name Changes of the Table
inputType2.Properties.RowNames = RowNamesInputType2;
% Row Name Assignment
fig = uifigure;
uit = uitable(fig, ...
'Data',inputType2, ...
'ColumnEditable',[true true], ...
'CellEditCallback',@cb_table_edit);
x = uit.Data;
In this case the CellEditCallback is called "cb_table_edit" and is defined as follows:
function cb_table_edit(src,~)
assignin('base','inputType2',src.Data);
end
If you are using MATLAB R2016b or later, you can define the function cb_table_edit in your script, along with your other code, but if you are using an earlier version of MATLAB, you'd need to put the code for cb_table_edit in its own m-file called cb_table_edit.m.

카테고리

Help CenterFile Exchange에서 App Building에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by