필터 지우기
필터 지우기

extracting one data point per day from a time series

조회 수: 4 (최근 30일)
Jenny
Jenny 2014년 3월 20일
댓글: Jenny 2014년 3월 24일
I have a time series of predicted water level data (cm), either 3 or 4 predicted values per day (for an entire year).
For each day I would like to extract only the highest predicted value along with the date/time stamp.
How do I extract the highest value for each day - and write that out to a new matrix?
An example of the data is attached in the extract_data.txt file.
Following that, I would like to bar chart the data per month.
I can do this manually - however, is there a way to select the data based on the date/time stamp and bar plot the data for that month ?
Is there a way to loop the plotting ?
Thank you, Jenny
  댓글 수: 1
dpb
dpb 2014년 3월 20일
You can't efficiently select a max value from the file directly; you don't have sufficient information at a time.
Read the file in its entirety, convert the timestamps to Matlab datenums (use datenum) and then group by the unique values found therein. Then for each of those groups find the max and its location and select those rows.

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

채택된 답변

per isakson
per isakson 2014년 3월 20일
This produces a bar chart
fid = fopen( 'cssm.txt', 'r' );
cac = textscan( fid, '%s%f', 'Delimiter' , '\t' );
fclose( fid );
vec = datevec( cac{1}, 'dd/mm/yyyy HH:MM:SS' );
day_of_year = @(vec) datenum(vec(:,1:3))-datenum(vec(1,1),1,0);
sl = accumarray( day_of_year(vec), cac{2}, [max(day_of_year(vec)),1], @max );
bar( sl )
xlabel( 'day of year' )
where cssm.txt is a copy of your file

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by