How to display an sql data Table in a uitable

5 ビュー (過去 30 日間)
Oussama Louati
Oussama Louati 2018 年 11 月 21 日
コメント済み: Kojiro Saito 2018 年 11 月 30 日
Hallo every one
How to Upload/ Display a an SQL data Table in a uitable,
Thank you in advance.

採用された回答

Kojiro Saito
Kojiro Saito 2018 年 11 月 27 日
From R2018a, we can display table array data in uitable.
The following is an example of reading data from PostgreSQL and show it in uitable.
%% Access to database
conn = database('db_name','usename', 'password', ...
'Vendor','PostgreSQL', ...
'Server','localhost','PortNumber',5432);
tableName = 'table_name';
% Read data from SQL
data = sqlread(conn, tableName);
%% plot in uitable
f = uifigure;
uit = uitable(f, 'Data', data);
  4 件のコメント
Oussama Louati
Oussama Louati 2018 年 11 月 28 日
After displaying the Table, I want the user to be able to select lines from this table,
I want than later to do something with the selected lines
Kojiro Saito
Kojiro Saito 2018 年 11 月 30 日
uitable has a property CellSelectionCallback, and by using this, selected lines can be caught up.
Here is an example of do something from selected lines (app.data and app.selected are properties added in AppDesigner)
app.UITable.CellSelectionCallback = {@selectedChange, app};
function selectedChange(src, eve, app)
% Get selected lines
app.selected = eve.Indices(:, 1);
% Extract only selected lines from original data
selectedData = app.data(app.selected, :);
% Do something on selected lines
% for example,
% m = mean(selectedData);
end

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

その他の回答 (1 件)

Oussama Louati
Oussama Louati 2018 年 11 月 27 日
Thank you very much Kojiro,
This Problem is solved and I'm facing a new one,
how to select Cells (lines) from the Table using Check Box ? ,
Thank you in advance.

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by