Updating UiTable - Table not Updated

11 views (last 30 days)
Fatih
Fatih on 13 Feb 2023
Answered: Voss on 13 Feb 2023
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 Comments
Voss
Voss on 13 Feb 2023
@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 on 13 Feb 2023
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.

Sign in to comment.

Answers (1)

Voss
Voss on 13 Feb 2023
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.

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!