Updating UiTable - Table not Updated
10 ビュー (過去 30 日間)
古いコメントを表示
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
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.
回答 (1 件)
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.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Migrate GUIDE Apps についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!