필터 지우기
필터 지우기

Extract Data from Timetable

조회 수: 102 (최근 30일)
Ioannis Tsikriteas
Ioannis Tsikriteas 2018년 6월 2일
댓글: Ioannis Tsikriteas 2018년 6월 4일
Hi, i have a daytime Matrix and i also have a second timetable of 2 columns (first Time, second Data) of dates from which i want to extract for each daytime of the first Matrix the Data that refers to this Date fromthe second one!
Is there an easy way, without using a for loop, to do so?
  댓글 수: 10
Peter Perkins
Peter Perkins 2018년 6월 4일
Ioannis, I'm pretty sure every loop in your code is unnecessary. For example:
y = NaT(somePreallocationSize);
i = isbetween(x-calyears(1),down,up);
y(i,5) = t(i,5);
I can't really follow everything that's in your code, but that's the idea. This will run MUCH faster and is much simpler to write and maintain.
Ioannis Tsikriteas
Ioannis Tsikriteas 2018년 6월 4일
Thank's a lot. You know...i am not as experienced in Matlab as you are. I wanted to add and to substract also to my dates 5 years. Indeed it was slow to execute all these loops but eventually it was a succesful attempt

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

채택된 답변

Paolo
Paolo 2018년 6월 2일
편집: Paolo 2018년 6월 2일
This example will help you.
A datetime matrix:
daytimemat = datetime(['13/04/2018';'25/04/2018';'28/04/2018'],'Format','dd/MM/yyyy');
A timetable with dates and data.
tt = timetable(datetime({'13/04/2018';'25/04/2018';'26/04/2018';'28/04/2018'}), [37.3;39.1;42.3;21]);
The following command:
%Use the index for which tt.Time and daytimemat are equal to find data.
tt.Var1(tt.Time(daytimemat))
outputs :
37.3000
39.1000
21.0000
which is the data contained in the timetable tt corresponding to the dates in daytimemat array.

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by