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

조회 수: 18 (최근 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 CenterFile Exchange에서 Develop 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