Matching string from multiple arrays
Mostrar comentarios más antiguos
Hi,
I have three structures with time stamps (char arrays, eg '2016-11-02 10:00:00') and corresponding datapoints of significant wave heights (double), and these are of different length for the three structures so I cannot just concatenate them.
Basically I want to make a new array with only the datapoint values where the correcpodning time stamp exists in all three of my structures' time stamp field .
I've used ismember and matrix multiplication for just two of the structures (see below), but I realise that I still have values in the array I'm checking against that doesn't exist in the thing I'm checking, so I still have uneven lengths of the arrays. I have 163 triplets of stuctures to check, hence the 'i' to be able to run through all of them eventually.
Drifter_okera5 = ismember(cellstr(Drifters(i).ObsTimestamp), cellstr(era5(i).timestamp)); % check if what is in drifters are in era5
DrifterHsera5 = Drifter_okera5.*Drifters(i).Hs'; % Take the resulting logical matrix and multiply it with the drifter HS
DrifterHsok = DrifterHs(DrifterHs~= 0); %remove all the values that are now zeros, these do not have a matching era5 hs
Any tips are most welcome!
3 comentarios
Adam Danz
el 8 de Sept. de 2020
Convert the date strings to datetime values which are much easier to work with.
If your timestamps and the associated data have different lengths, how do you know how the data corresponds to the timestamps?
Kerstin Bergentz
el 8 de Sept. de 2020
Adam Danz
el 14 de Sept. de 2020
See my answer below.
Respuesta aceptada
Más respuestas (1)
Steven Lord
el 17 de Sept. de 2020
0 votos
If you have your data stored in timetable arrays, call synchronize with your three timetable arrays as input and specify the newTimeBasis input as 'intersection'.
Categorías
Más información sobre Data Type Conversion en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!