필터 지우기
필터 지우기

Create the matrix with aligned dates

조회 수: 5 (최근 30일)
Luca Re
Luca Re 2023년 6월 4일
댓글: the cyclist 2023년 6월 7일
hi,i've this problem to solve
i've a matrix of date (see pics) A (row) * B(columns)
i used datetime in this matrix
Each date vector can start and end at a different time
I want to synchronize the dates so that each row corresponds to the same date (
example:
Or if it becomes complicated to shift them up or down n boxes, place them side by side with an index (see pics below)
  댓글 수: 6
Luca Re
Luca Re 2023년 6월 4일
편집: Luca Re 2023년 6월 4일
>> A=load("TEST_A.mat");
>> D=load("TEST_B.mat");
>> TEST_sYNCRONIZE
Incorrect number or types of inputs or outputs for function 'synchronize'.
Error in TEST_sYNCRONIZE (line 7)
synchronize(A,D,'union','linear')
i try to union array with different size but it give me error..
According to the documentation it says to use the 'union' and 'linear' command if the vectors don't have linear dimensions
I was wrong.. i don't know the reason but i have to use A.A and D.D to recall the data But it doesn't work the same
Luca Re
Luca Re 2023년 6월 6일
이동: the cyclist 2023년 6월 6일
hi, i attach file .m with data to syncronized
i try to syncronized it but it give me error
Someone can help me? thanks
i want this result (see pics below)

댓글을 달려면 로그인하십시오.

답변 (1개)

the cyclist
the cyclist 2023년 6월 6일
load SyncronizedData.mat
for nc = 2:width(J)
[tf,loc] = ismember(J(:,nc),J(:,nc-1));
tmp = J(:,nc);
J(:,nc) = {'NaT'};
J(loc(tf),nc) = tmp(tf);
end
J(all(strcmp(J,'NaT'),2),:)=[]
J = 7×3 cell array
{'13-Jan-2008'} {'13-Jan-2008'} {'NaT' } {'14-Jan-2008'} {'14-Jan-2008'} {'NaT' } {'15-Jan-2008'} {'15-Jan-2008'} {'15-Jan-2008'} {'16-Jan-2008'} {'16-Jan-2008'} {'16-Jan-2008'} {'17-Jan-2008'} {'17-Jan-2008'} {'17-Jan-2008'} {'18-Jan-2008'} {'18-Jan-2008'} {'18-Jan-2008'} {'19-Jan-2008'} {'19-Jan-2008'} {'19-Jan-2008'}
  댓글 수: 2
Luca Re
Luca Re 2023년 6월 7일
I'm having trouble replicating your results
load SyncronizedData.mat
J =
struct with fields:
J: {9×3 cell}
>> J.J
ans =
9×3 cell array
{'NaT' } {'NaT' } {'NaT' }
{'13-Jan-2008'} {'13-Jan-2008'} {'NaT' }
{'14-Jan-2008'} {'14-Jan-2008'} {'NaT' }
{'15-Jan-2008'} {'15-Jan-2008'} {'15-Jan-2008'}
{'16-Jan-2008'} {'16-Jan-2008'} {'16-Jan-2008'}
{'17-Jan-2008'} {'17-Jan-2008'} {'17-Jan-2008'}
{'18-Jan-2008'} {'18-Jan-2008'} {'18-Jan-2008'}
{'19-Jan-2008'} {'19-Jan-2008'} {'19-Jan-2008'}
{'NaT' } {'NaT' } {'NaT' }
should I use J.J instead of J?
the cyclist
the cyclist 2023년 6월 7일
I'm not sure why you save something different in the file you upload than you did in the file you are using. But, yes, it looks like J.J should work.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by