필터 지우기
필터 지우기

Splitting data into sets of 20 to store in a variable

조회 수: 2 (최근 30일)
Killian Flynn
Killian Flynn 2022년 11월 27일
댓글: Walter Roberson 2022년 11월 27일
Hello I am trying to split the data from Open, High, Low and Close into sets of every 20 days. I want DataE20 (data every 20 days) to look something like this:
day1 day2 ..... day21
DataE20(1) = Open(1) Open(2) ..... Open(21)
High(1) High(2) ..... High(21)
Low(1) Low(2) ..... Low(21)
Close(2) Close(2) ..... Close(20)
day22 day23 ..... day42
DataE20(2) = Open(22) Open(23) ..... Open(42)
High(22) High(23) ..... High(42)
Low(22) Low(23) ..... Low(42)
Close(22) Close(23) ..... Close(42)
and so on until DataE20 cant go any longer.
data =readtable('EURUSD=X.csv')
Open = data(:,2);
High= data(:,3);
Low = data(:,4);
Close = data(:,5);
stackedplot(Open)
Data20(1:height(Open)/20) =
I have attached what the table looks like. Any help would be greatly appreciated.

채택된 답변

Walter Roberson
Walter Roberson 2022년 11월 27일
Dates = data.Date;
dayoffset = days(Dates - Dates(1));
G = floor(dayoffset/20) + 1;
DataE20 = splitapply(@(Date,Open,High,Low,Close,AdjClose,Volume) {[Open,High,Low,Close].'}, Data, G);
The difference between this and what you layed out is that this does not assume that data is present for all dates. It groups by 20 consecutive dates, not by 20 consecutive file entries. The file appears to not have entries for weekends. My code will not split by 20 entries (4 calendar weeks if the only missing entries correspond to weekends), it splits by 20 days (slightly less than 3 calendar weeks), which is what you asked for.
  댓글 수: 5
Walter Roberson
Walter Roberson 2022년 11월 27일
G = floor((0:height(data)-1)/20).' + 1;
Walter Roberson
Walter Roberson 2022년 11월 27일
G = floor((0:height(data)-1)/20).' + 1;

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by