Data sorting by time
34 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Dears,
I have two tables labeled as Details & Finaldata. I want to rearrange the Details & Finaldata according to the time (assending order) in Details table (Column3). Kindly some one help how to do this. Many many thanks in advance.
Details:
73268 p.vc008k1e7t0 2014-10-20 00:27:20.597
73269 p.vc002k50e4t0 2014-10-20 00:40:57.592
83318 p.vc008k30e4t3r 2015-03-24 22:26:15.492
83320 p.vc008k30e4t4r 2015-03-24 22:33:09.896
83445 p.vc001k1e5t0 2015-03-27 06:12:21.340
74282 p.vb001k1e5t0 2014-10-30 17:16:03.727
83446 p.vl00nk1e5t0 2015-03-27 06:41:08.516
83447 p.vl00nk1e5t1 2015-03-27 07:12:10.958
83448 p.vl00nk1e5t0 2015-03-27 07:34:44.090
80617 p.vl00nk1e5t1 2014-11-26 12:24:45.325
80618 p.vl00nk1e5t2 2014-12-01 00:53:45.365
Finaldata:
0.3 0.25
0.1 0.65
0.02 0.54
0.5 1.35
0.6 2.98
0.8 0.3
10.3 0.1
2.36 0.6
2.3 1.5
5.63 10.2
2.58 11.0
0 comentarios
Respuestas (1)
Stephen23
el 1 de Mayo de 2015
Editada: Stephen23
el 2 de Mayo de 2015
Sorting these timestamps into order is really easy, because actually you do not need to convert to date numbers or numeric values at all! You can simply apply sortrows directly to the data table.
This is because that particular date format can be sorted into date/time order simply by using a standard character sort, because it naturally progresses from the highest unit to the lowest unit. This format is essentially the ISO 8601 date format, and the fact it can be sorted into time/date order without any conversions being applied is one of its main advantages. Note this does not apply to other date formats.
I do not have tables in my MATLAB version, but sortrows can also be applied to tables:
A ={73268, 'p.vc008k1e7t0', '2014-10-20 00:27:20.597';
73269, 'p.vc002k50e4t0', '2014-10-20 00:40:57.592';
83318, 'p.vc008k30e4t3r','2015-03-24 22:26:15.492';
83320, 'p.vc008k30e4t4r','2015-03-24 22:33:09.896';
83445, 'p.vc001k1e5t0', '2015-03-27 06:12:21.340';
74282, 'p.vb001k1e5t0', '2014-10-30 17:16:03.727';
83446, 'p.vl00nk1e5t0', '2015-03-27 06:41:08.516';
83447, 'p.vl00nk1e5t1', '2015-03-27 07:12:10.958';
83448, 'p.vl00nk1e5t0', '2015-03-27 07:34:44.090';
80617, 'p.vl00nk1e5t1', '2014-11-26 12:24:45.325';
80618, 'p.vl00nk1e5t2', '2014-12-01 00:53:45.365'};
>> [out,idx] = sortrows(A,3) % 3 picks the column that we want to sort by
out =
[73268] 'p.vc008k1e7t0' '2014-10-20 00:27:20.597'
[73269] 'p.vc002k50e4t0' '2014-10-20 00:40:57.592'
[74282] 'p.vb001k1e5t0' '2014-10-30 17:16:03.727'
[80617] 'p.vl00nk1e5t1' '2014-11-26 12:24:45.325'
[80618] 'p.vl00nk1e5t2' '2014-12-01 00:53:45.365'
[83318] 'p.vc008k30e4t3r' '2015-03-24 22:26:15.492'
[83320] 'p.vc008k30e4t4r' '2015-03-24 22:33:09.896'
[83445] 'p.vc001k1e5t0' '2015-03-27 06:12:21.340'
[83446] 'p.vl00nk1e5t0' '2015-03-27 06:41:08.516'
[83447] 'p.vl00nk1e5t1' '2015-03-27 07:12:10.958'
[83448] 'p.vl00nk1e5t0' '2015-03-27 07:34:44.090'
And that is it no conversions required! To sort another table with the same order, just use the second output idx:
other_table(idx,:)
0 comentarios
Ver también
Categorías
Más información sobre Data Distribution Plots en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!