Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Entry new date when date is a different day from previous entry

1 回表示 (過去 30 日間)
Victor Lejona
Victor Lejona 2017 年 9 月 12 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I have the array in the first picture (the one with only 2 rows) and would like to convert it to the array in the second picture (the one with 5 rows).
Many thanks in advance Victor

回答 (3 件)

Steven Lord
Steven Lord 2017 年 9 月 12 日
I can't be certain, since your formatting isn't very clear, but are you trying to do something like this? You may want to transpose tableOfStartAndEndTimes, depending on how you want your data to be shown.
% sample data
x = datetime(2017, 9, 1) + hours(0:6:24);
tableOfStartAndEndTimes = [x(1:end-1); x(2:end)]
  1 件のコメント
Victor Lejona
Victor Lejona 2017 年 9 月 12 日
Hi Steven, I've updated the question with a couple of images, didn't realise about the wrong format.
Thanks, Victor

Walter Roberson
Walter Roberson 2017 年 9 月 12 日
You can do calculations such as
for K = length(StartDate) : -1 : 1
end_of_day = dateshift(StartDate(K), 'end', 'day');
if end_of_day < EndDate(K)
StartDate = [StartDate(1:K); end_of_day; StartDate(K+1:end)];
EndDate = [EndDate(1:K-1); end_of_day; EndDate(K:end)];
end
end
This works backwards breaking the entries as it goes. It does assume that the end date is at most the next day, not several days from now.
Working backwards doing insertions avoids a common off-by-one error that occurs if you work forward doing insertions.

Peter Perkins
Peter Perkins 2017 年 9 月 14 日
You question is not described very clearly. It LOOKS like you want to split those start/end pairs into two pairs if they cross a midnight. Except that in one image you have 9/10/2016 11:10 and in the other you have 10/10/2016 11:10.
I think you need to clearly state what you want.

この質問は閉じられています。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by