How can I make a table editable in app designer to use the resulting data matrix?

216 ビュー (過去 30 日間)
Cedric Kotitschke
Cedric Kotitschke 2018 年 10 月 1 日
コメント済み: Jafet Bolaños 2022 年 9 月 28 日

I am using app designer and wanted to create a table but all I can do is change the column titles. I want the user to be able to insert data into the table which is then used by a function. Neither can I change anything in design view (UI figure properties menu) nor can I channge anything in code view (everything is this you-can't-edit-this-grey. Can you help?

回答 (5 件)

Eric
Eric 2019 年 7 月 29 日
It seems you must first add "default" data (via something like the startupFcn for your UIFigure) before you can edit the data (so you cannot put in default data in the Design View). For example:
app.UITable.Data = zeros(n,numel(app.UITable.ColumnName));
will fill in n rows of zeros, which you can edit depending on your ColumnEditable settings.
You can also add a "+" and "-" buttons to your app to add/delete rows. In the callback for these buttons, you can do
app.UITable.Data(end+1,:) = 0; % Add Row of zeros
% or
app.UITable.Data(end,:) = []; % Delete Row
depending on the button.

Freya H
Freya H 2018 年 10 月 24 日
The following code might solve your problem. You can use the feature 'ColumnEditable' of a uitable to make some or all columns editable.
% Set Editable
ncols = size(app.UITable.Data,2);
app.UITable.ColumnEditable = true(1,ncols); %all columns editable
app.UITable.ColumnEditable(2) = false; %column2 non-editable
The data is stored in app.UITable.Data.

Vishal Sharma
Vishal Sharma 2020 年 4 月 6 日
if the given coloumn is horizontal, i.e
app.UITable.ColumnName={};
app.UITable.RowName={'N' 'N/m'};
then how to make one particular row editable?
  3 件のコメント
Vishal Sharma
Vishal Sharma 2020 年 4 月 6 日
thanks a lot Eric.
yeah i guess there is no straightforward way to make row Editable.
i was doing it the hard way, splitting the table into 2 different tables and making one table editable, while leaving other non-editable(facepalm)
Eric Sargent
Eric Sargent 2020 年 12 月 9 日
Why not just transpose the table data?
Given a table of data & variable names named "dataTable" that you want to put into a uitable of your app:
y = rows2vars(dataTable);
y.Properties.RowNames = y.OriginalVariableNames;
y = removevars(y,"OriginalVariableNames");
uit = uitable(app.UIFigure);
uit.Data = y;
uit.RowName = y.Properties.RowNames;
uit.ColumnName = y.Properties.ColumnNames;
You can set the ColumnEditable property on/off per row of dataTable.

サインインしてコメントする。


Eric Sargent
Eric Sargent 2020 年 12 月 9 日
You can now edit additional properties of a UITable in an App Designer app, such as RowName and ColumnEditable.

Jeet Shetty
Jeet Shetty 2021 年 7 月 9 日
hey guys, i have a similar doubt regarding editting a table but my table is not present on the app from the begining , it shows up after i enter the no . of sensor on my app. I want to now edit this table to enter the X and Y values , such that i can plot the those values on the graph. How can i do it?
properties (Access = private)
sensor_table = gobjects(1,1); %initialize as graphics object
end
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: Button
function ButtonPushed(app, event)
N = app.NoofSensorsEditField.Value
sensor_number = (1:N).';
x_coordinate = zeros(N,1)
y_coordinate = zeros(N,1)
T = table(sensor_number, x_coordinate, y_coordinate)
app.sensor_table = uitable(app.UIFigure, 'Data', T)
  3 件のコメント
Jeet Shetty
Jeet Shetty 2021 年 7 月 14 日
Yes thank you i figured that out. I'm trying to save the new values and plot them on the graph, I'm stuck on that . I was thinking about using another push button to save the new values and plot it on the graph but I'm not sure on how i should code it . If you could help with that , I'd appreciate it Nevertheless thank you for your help
Allamaprabhu Ani
Allamaprabhu Ani 2021 年 11 月 28 日
@Jeet Shetty Did you figure it out? I have the same question.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by