Table resorting after deleting selected rows from the sorted Table

3 visualizaciones (últimos 30 días)
Venkatesan
Venkatesan el 23 de Abr. de 2025
Comentada: Cris LaPierre el 24 de Abr. de 2025
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?

Respuestas (1)

Cris LaPierre
Cris LaPierre el 23 de Abr. de 2025
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 = 100x10 table
LastName Gender Age Location Height Weight Smoker Systolic Diastolic SelfAssessedHealthStatus ____________ __________ ___ _____________________________ ______ ______ ______ ________ _________ ________________________ {'Robinson'} {'Male' } 50 {'County General Hospital' } 68 172 false 125 76 {'Good' } {'Reed' } {'Male' } 50 {'VA Hospital' } 72 186 true 129 89 {'Excellent'} {'Brown' } {'Female'} 49 {'County General Hospital' } 64 119 false 122 80 {'Good' } {'Stewart' } {'Male' } 49 {'County General Hospital' } 68 170 true 129 95 {'Poor' } {'Hughes' } {'Female'} 49 {'County General Hospital' } 63 123 true 128 96 {'Good' } {'Griffin' } {'Male' } 49 {'County General Hospital' } 70 186 false 119 74 {'Fair' } {'Martin' } {'Male' } 48 {'VA Hospital' } 71 181 true 130 92 {'Good' } {'Clark' } {'Female'} 48 {'VA Hospital' } 65 133 false 121 75 {'Excellent'} {'Adams' } {'Female'} 48 {'VA Hospital' } 66 137 false 127 83 {'Excellent'} {'Ramirez' } {'Female'} 48 {'County General Hospital' } 64 137 true 138 82 {'Excellent'} {'Ross' } {'Female'} 48 {'VA Hospital' } 64 126 false 118 79 {'Good' } {'Gonzales'} {'Male' } 48 {'County General Hospital' } 71 174 false 123 79 {'Good' } {'Bryant' } {'Female'} 48 {'County General Hospital' } 66 134 false 129 73 {'Excellent'} {'Hayes' } {'Male' } 48 {'County General Hospital' } 66 177 false 114 86 {'Fair' } {'Scott' } {'Male' } 47 {'St. Mary's Medical Center'} 70 187 false 127 84 {'Excellent'} {'Rogers' } {'Female'} 47 {'VA Hospital' } 66 147 false 117 86 {'Excellent'}
T(T.Age>45,:)=[]
T = 83x10 table
LastName Gender Age Location Height Weight Smoker Systolic Diastolic SelfAssessedHealthStatus ____________ __________ ___ _____________________________ ______ ______ ______ ________ _________ ________________________ {'Anderson'} {'Female'} 45 {'County General Hospital' } 68 128 false 114 77 {'Excellent'} {'Wright' } {'Female'} 45 {'VA Hospital' } 70 126 true 134 92 {'Excellent'} {'Phillips'} {'Male' } 45 {'VA Hospital' } 67 172 false 117 89 {'Good' } {'Bell' } {'Male' } 45 {'St. Mary's Medical Center'} 70 170 true 138 82 {'Good' } {'Torres' } {'Female'} 45 {'County General Hospital' } 70 137 false 119 79 {'Excellent'} {'Simmons' } {'Male' } 45 {'VA Hospital' } 71 181 false 124 77 {'Excellent'} {'Diaz' } {'Male' } 45 {'County General Hospital' } 68 172 true 136 93 {'Good' } {'Lee' } {'Female'} 44 {'County General Hospital' } 66 146 true 128 90 {'Fair' } {'Green' } {'Male' } 44 {'County General Hospital' } 71 193 false 121 92 {'Good' } {'Baker' } {'Male' } 44 {'VA Hospital' } 71 192 true 136 90 {'Good' } {'Perez' } {'Male' } 44 {'VA Hospital' } 69 183 false 116 80 {'Excellent'} {'Roberts' } {'Male' } 44 {'VA Hospital' } 70 169 true 132 89 {'Good' } {'Sanchez' } {'Female'} 44 {'St. Mary's Medical Center'} 62 136 true 130 91 {'Good' } {'Russell' } {'Male' } 44 {'VA Hospital' } 69 188 true 124 92 {'Good' } {'Johnson' } {'Male' } 43 {'VA Hospital' } 69 163 false 109 77 {'Fair' } {'Morris' } {'Female'} 43 {'County General Hospital' } 64 135 true 132 91 {'Poor' }
  6 comentarios
Stephen23
Stephen23 el 24 de Abr. de 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
Cris LaPierre el 24 de Abr. de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Environment and Settings en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by