How can I filter a date column so it just considers every 5 minutes observations for each day?

조회 수: 4 (최근 30일)
Hi everyone!
I have the next column where each number represents the date ('yyyymmddHHMM' in this order):
As you can see from the image here I have one year (1990), one month (january), two days (02 and 03) and different hours with one minute distance.
What I wanted to do is to filter this column for every 5 minutes. First starting every day in the first minute (10:00 vs 10:05) and continuing with the second minute (10:01 vs 10:06) and so on.
I have used the next comand to filter my data:
C5= cell(length(C)-2,1);
for ii=1:length(C5)
C5{ii} = C(ii:5:end)';
end
Obtaining the next results:
But as you can see my command is not restarting the 5 minutes jump when is another day and therefore the columns are "outdated" for my purposes.
For example, the first column form the last image should look this:
How can I modify my code so it restarts the 5 minutes jumps when is another day?
Thanks a lot for your help!
AngelaT
  댓글 수: 2
Azzi Abdelmalek
Azzi Abdelmalek 2016년 4월 30일
Posting images is not useful for someone who wants test your data. It easier for everyone if you post your data with the format you are using in Matlab (just copy and paste your data), we have not to ask if it's a cell array containing double or char variables.
angelavtc
angelavtc 2016년 4월 30일
편집: angelavtc 2016년 4월 30일
OK then this is the original data type 32*1 double: [199001021000.000; 199001021001.000; 199001021002.000; 199001021003.000; 199001021004.000; 199001021005.000; 199001021006.000; 199001021007.000; 199001021008.000; 199001021009.000; 199001021010.000; 199001021011.000; 199001021012.000; 199001021013.000; 199001021014.000; 199001021015.000; 199001031000.000; 199001031001.000; 199001031002.000; 199001031003.000; 199001031004.000; 199001031005.000; 199001031006.000; 199001031007.000; 199001031008.000; 199001031009.000; 199001031010.000; 199001031011.000; 199001031012.000; 199001031013.000; 199001031014.000; 199001031015.000]
And this is the code that I use:
C5= cell(length(C),1);
for ii=1:length(C5);
C5{ii} = C(ii:5:end)';
end
And the one that give me the unwanted result that I mentioned before.
Thanks

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

채택된 답변

CS Researcher
CS Researcher 2016년 4월 30일
편집: CS Researcher 2016년 4월 30일
You can use the mod operator. Lets say the data vector is x and it needs to rearranged in C. Try the following:
C = cell(1,5); % Pre-allocate the cell array
for i = 1:5
C{1,i} = x(mod(x,5) == i-1);
end
Hope this helps!
  댓글 수: 2
angelavtc
angelavtc 2016년 4월 30일
편집: Azzi Abdelmalek 2016년 4월 30일
@CS Researcher that is perfect, but it gives me cells in columns, like this:
[199001021000.000;199001021005.000;199001021010.000;199001021015.000;199001031000.000;199001031005.000;199001031010.000;199001031015.000]
[199001021001.000;199001021006.000;199001021011.000;199001031001.000;199001031006.000;199001031011.000]
[199001021002.000;199001021007.000;199001021012.000;199001031002.000;199001031007.000;199001031012.000]
[199001021003.000;199001021008.000;199001021013.000;199001031003.000;199001031008.000;199001031013.000]
[199001021004.000;199001021009.000;199001021014.000;199001031004.000;199001031009.000;199001031014.000]
I would like to substitute the ";" for "," Can you help me with this? The final code that I used was this:
C5 = cell(1,5); % Pre-allocate the cell array
for i = 1:5
C5{:,i} = C(mod(C,5) == i-1);
end
C6=C5'
angelavtc
angelavtc 2016년 4월 30일
Done, I tried this and it works:
for ii=1:5
C6{ii} = C6{ii}';
end
Thanks a lot to all of you, you really helped me a lot!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by