Table resorting after deleting selected rows from the sorted Table
Show older comments
I have a table data with gender and age.
First I will sort in descending based on age and I will select above 60 age of peoples and delete it.
Now I want to see the remaining data with same sorting(descending order based on age) on the table .
Here, The table property not able to set as Descending order sort through code.
Could you please help us for this issue?
Answers (1)
You haven't shared the code you are using to complete your tasks. That will allow us to say why it is happening.
However, here is code I would use to sort then delete rows from a table. As you can see, the final table is still sorted in desceding age order.
T = readtable('patients.xls');
T = sortrows(T,"Age",'descend')
T(T.Age>45,:)=[]
6 Comments
Venkatesan
on 23 Apr 2025
dpb
on 23 Apr 2025
Instead of the whole app, just pull out the specific code for the table and paste it as text (remembering to format as code) so folks can see here what you did...
Cris LaPierre
on 23 Apr 2025
Edited: Cris LaPierre
on 23 Apr 2025
I think the best thing to do is point you to this answer: https://www.mathworks.com/matlabcentral/answers/2068161-how-do-programatically-sort-a-uitable
I don't know if it is possible to programmatically sort a uitable this way. It appears you need to first sort the data then add it to the uitable.
Note that sorting a uitable only changes how the table is displayed. It does not actually sort the table data.
You could simplify the delete at least
% Key press function: UITable
function UITableKeyPress(app, event)
key = event.Key;
selection = app.UITable.Selection;
if ~isempty(selection) && strcmp(key, 'delete')
app.UITable.Data(selection,:) = [];
end
end
Venkatesan
on 24 Apr 2025
Stephen23
on 24 Apr 2025
"So, I have to show the Age Column and down Arrow to represent the "Descending order" by the code without manual intervention."
or
Cris LaPierre
on 24 Apr 2025
I understand what you want. I just don't know that there is a documented approach that achieves it programmatically.
Rather than use the column headers to sort the table, you could implement a programmatic sort of the data with app buttons and custom callbacks. This will meet your design requirements, though the arrow still won't appear. Instead, a dropdown menu where you selected the sort order would indicate it.
Here's I've implemented a solution and removed all those who are 48.

Categories
Find more on Environment and Settings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!