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

18 visualizaciones (últimos 30 días)
Ismaeel
Ismaeel el 20 de En. de 2022
Respondida: Nathan Gyger el 9 de Dic. de 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.

Respuestas (2)

KSSV
KSSV el 20 de En. de 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 comentario
Ismaeel
Ismaeel el 20 de En. de 2022
Editada: Ismaeel el 20 de En. de 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.

Iniciar sesión para comentar.


Nathan Gyger
Nathan Gyger el 9 de Dic. de 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.

Categorías

Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by