How to sort and save the sorted table in app designer?

16 ビュー (過去 30 日間)
Ismaeel
Ismaeel 2022 年 1 月 20 日
回答済み: Nathan Gyger 2022 年 12 月 9 日
I am using "uitable" to display an editable and sortable table after reading data from an excel sheet. However, when I sort the data which works fine (using the vertical arrow on the top of each column), it works fine but cannot save the table in the new order of rows (it only save the edited data using the original order of rows). Any idea? I am using the latest version of MATLAB. Thanks.

回答 (2 件)

KSSV
KSSV 2022 年 1 月 20 日
idx = randperm(10)' ;
x = rand(10,1) ;
T = table(idx,x)
T = 10×2 table
idx x ___ ________ 9 0.065109 5 0.67649 3 0.76369 8 0.95726 4 0.6604 1 0.52381 10 0.90536 6 0.23863 2 0.20491 7 0.42844
[val,idx] = sort(T.(1)) ;
T = T(idx,:)
T = 10×2 table
idx x ___ ________ 1 0.52381 2 0.20491 3 0.76369 4 0.6604 5 0.67649 6 0.23863 7 0.42844 8 0.95726 9 0.065109 10 0.90536
  1 件のコメント
Ismaeel
Ismaeel 2022 年 1 月 20 日
編集済み: Ismaeel 2022 年 1 月 20 日
Thank you KSSV for your reply. I am using uitable in the app designer. I am sorting the table accoridng to a column I select using the arrow on the top of the column. Then I push a "save" button I created to save the just-sorted data to an Excel sheet using "writecell" or "writetable" functions. The sorting does not take place programmically as in your example, rather I use the GUI sorting option. There is no problem in saving the edited table but it only saves the edited data using the same order of the rows. As you know, when you sort a table, the order of rows changes.

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


Nathan Gyger
Nathan Gyger 2022 年 12 月 9 日
Hi Ismaeel,
You can use the DisplayData property of the uitable as this always holds a table that is sorted in the same order as it is selected in the ui.

カテゴリ

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

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by