struct2table and data preservation

I am working with time sensitive data which is in struct form. I imported my data directly using struct2table function so I will be able to use the 'sortrows' function specifically for the table data structure. I then decided to reverser the process by using table2struct, I am wondering if the sequence/sorting will be preserved after converting back to struct. I sorted by date/time. I want to know if the conversion will mess with the sorting.

댓글 수: 3

Walter Roberson
Walter Roberson 2020년 2월 4일
If you are sorting a table by date/time then it might possibly make more sense to use a timetable than a plain table, depending on the processing you are doing.
When you convert the resulting timetable to plain table, and then table2struct, the order would be sorted by the time key.
If for some reason you need to get back the original order, then before sorting add a column that is the row index; then you could sort by that to get your original order.
Stephen23
Stephen23 2020년 2월 5일
Reuben Addison's "Answer" moved here:
Thanks, I will try it
You can also avoid converting to and from the table. You can sort directly as follows.
Assuming that time is of type date/time or numeric
[~,index] = sort([mystruct.time]);
mysortedstruct = mystruct(index);

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

제품

릴리스

R2018a

질문:

2020년 2월 4일

댓글:

2020년 2월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by