How can I merge two structs?
40 visualizzazioni (ultimi 30 giorni)
My question might become a bit complicated, so please let me know if I have not explained something well.
I have got a structure that has two relevant fields, one field is a character which shows the date and the other field is a structure with data, let's call them A.date (char) and A.data (struct).
Some of the dates are duplicate (on purpose) I would like to add the values from the structure of those duplicates to the structure with the same date (so effectively merging the structures).
Sketch of what I'd like to achieve:
if A(i).date == A(i+1).date % Will work untill final value is reached
A(i).data + A(i+1).data % Won't work, but I would want to merge A(i).data + A(i+1).data
Any help is greatly appreciated, thanks in advance!
Benjamin Thompson il 11 Ott 2022
Due to the need to merge it might be easiest to use struct2table, table2timetable, make sure it is merged well as a time table, then table2struct to change it back to the struct data type.