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

20 Ansichten (letzte 30 Tage)
Ismaeel
Ismaeel am 20 Jan. 2022
Beantwortet: Nathan Gyger am 9 Dez. 2022
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.

Antworten (2)

KSSV
KSSV am 20 Jan. 2022
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 Kommentar
Ismaeel
Ismaeel am 20 Jan. 2022
Bearbeitet: Ismaeel am 20 Jan. 2022
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.

Melden Sie sich an, um zu kommentieren.


Nathan Gyger
Nathan Gyger am 9 Dez. 2022
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.

Kategorien

Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by