Effacer les filtres
Effacer les filtres

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

21 vues (au cours des 30 derniers jours)
Ismaeel
Ismaeel le 20 Jan 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.

Réponses (2)

KSSV
KSSV le 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 commentaire
Ismaeel
Ismaeel le 20 Jan 2022
Modifié(e) : Ismaeel le 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.

Connectez-vous pour commenter.


Nathan Gyger
Nathan Gyger le 9 Déc 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.

Catégories

En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by