Create the matrix with aligned dates
조회 수: 5 (최근 30일)
이전 댓글 표시
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1402679/image.png)
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1402684/image.png)
Or if it becomes complicated to shift them up or down n boxes, place them side by side with an index (see pics below)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1402689/image.png)
댓글 수: 6
답변 (1개)
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),:)=[]
댓글 수: 2
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 Center 및 File Exchange에서 Text Files에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!