align two 3D arrays based on datenum

1 visualización (últimos 30 días)
Nina Schuback
Nina Schuback el 2 de Jul. de 2020
Respondida: Rik el 3 de Jul. de 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.

Respuesta aceptada

Rik
Rik el 3 de Jul. de 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);

Más respuestas (0)

Categorías

Más información sobre Dates and Time en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by