# how to extract previous week and month number of same hour?

조회 수: 2(최근 30일)
MUKESH KUMAR 16 Jun 2020
댓글: MUKESH KUMAR 18 Jun 2020
I had load data of one year, half houly data of load (1*17520), I want to add a column having load data of previous week (same day & time period) and another column having previous day data at same time slot
We can keep blank for initial week/day data because for that previous data is not available here.

#### 댓글 수: 5

표시 이전 댓글 수: 2
KALYAN ACHARJYA 16 Jun 2020
You can do it in multiple ways, it would be better to clear, if you can attach one same file
MUKESH KUMAR 16 Jun 2020
Ok sure
Steven Lord 17 Jun 2020
KSSV: if MUKESH KUMAR has the date and time data stored as a datetime array or as the time vector in a timetable, there's no need to split that data to jump backwards a day or a week.
d = datetime('now')
dMinusWeek = d - calweeks(1)
dMinusDay = d - caldays(1)

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

### 채택된 답변

Sujay C Sharma 17 Jun 2020
Hi,
Since the number of load entries per day is fixed at 48 (half-hourly data), this can be done using the circshift function on the load column in your data. Here is an example of how you can use circshift to achieve what you want:
NumEntriesPerDay = 48;
DataPrevDay = circshift(data,NumEntriesPerDay*1);
DataPrevDay(1:NumEntriesPerDay*1) = NaN;
DataPrevWeek = circshift(data,NumEntriesPerDay*7);
DataPrevWeek(1:NumEntriesPerDay*7) = NaN;

#### 댓글 수: 1

MUKESH KUMAR 18 Jun 2020
thanks

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

### Community Treasure Hunt

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

Start Hunting!

Translated by