align two 3D arrays based on datenum

1 view (last 30 days)
Nina Schuback
Nina Schuback on 2 Jul 2020
Answered: Rik on 3 Jul 2020
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.

Accepted Answer

Rik
Rik on 3 Jul 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);

More Answers (0)

Categories

Find more on Dates and Time in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!