align two 3D arrays based on datenum

조회 수: 1 (최근 30일)
Nina Schuback
Nina Schuback 2020년 7월 2일
답변: Rik 2020년 7월 3일
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.

채택된 답변

Rik
Rik 2020년 7월 3일
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개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by