align two 3D arrays based on datenum
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have two 3D arrays, 492 x 212 x 4 and 492 x 197 x 2.
In both, the first sheet is the date, where columns have the same date. The other sheets are corresponding data.
Array one has a few dates (colums) which are not in array 2, and array 2 has a few dates (columns) which are not in array 1.
I simply want to get rid of those, and end up with two arrays of the same row x colum size.
0 commentaires
Réponse acceptée
Rik
le 3 Juil 2020
You have some duplicate dates in your dataset, so that complicates matters a bit. The code below will match the two arrays.
%load data
s=load('bats_example.mat');
BATS_chla=s.BATS_chla;
BATS_nFLH=s.BATS_nFLH;
%keep only matching dates
date_chla=BATS_chla(1,:,1);
date_nFLH=BATS_nFLH(1,:,1);
a=ismember(date_nFLH,date_chla);
b=ismember(date_chla,date_nFLH);
BATS_nFLH=BATS_nFLH(:,a,:);
BATS_chla=BATS_chla(:,b,:);
%remove duplicate dates (keep the first)
date_chla=BATS_chla(1,:,1);
[~,idx]=unique(date_chla,'stable');
BATS_chla=BATS_chla(:,idx,:);
date_nFLH=BATS_nFLH(1,:,1);
[~,idx]=unique(date_nFLH,'stable');
BATS_nFLH=BATS_nFLH(:,idx,:);
%concatenate
output=cat(3,BATS_nFLH,BATS_chla);
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Dates and Time dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!