Extract Data from Timetable
古いコメントを表示
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 件のコメント
dpb
2018 年 6 月 2 日
Yes
Ioannis Tsikriteas
2018 年 6 月 2 日
Paolo
2018 年 6 月 2 日
Can you share the code for what you have tried so far?
Ioannis Tsikriteas
2018 年 6 月 2 日
Paolo
2018 年 6 月 2 日
An example:
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:
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.
Does this help?
Ioannis Tsikriteas
2018 年 6 月 2 日
編集済み: Ioannis Tsikriteas
2018 年 6 月 2 日
@Ioannis, I have submitted an answer for the original question. If that solved the problem, please accept it so it will be easily visible to other users (rather than having the solution in the comment section).
As for your second question, I was unable to replicate the problem.
x = datetime('08-Jul-2012 00:19:59','Format','dd-MMM-yyyy hh:mm:ss');
x = addtodate(datenum(x),-1,'year');
datestr(x)
The output is:
08-Jul-2011 00:19:59
Ioannis Tsikriteas
2018 年 6 月 2 日
編集済み: Ioannis Tsikriteas
2018 年 6 月 2 日
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
2018 年 6 月 4 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
