フィルターのクリア

Create new table wit differentiate or diff from existing timetable

20 ビュー (過去 30 日間)
Daniel Ubbink
Daniel Ubbink 2019 年 8 月 28 日
コメント済み: Olavo 2023 年 8 月 22 日
I've got below timetable with daily measurements from my gas meter at home:
Timestamps GasM3
____________________ _____________
14-Aug-2019 00:00:00 331.15
25-Aug-2019 00:00:00 332.37
26-Aug-2019 00:00:00 332.74
27-Aug-2019 00:00:00 333.97
I would like to know the daily consumption, so I tried playing with "differentiate" & "diff" to get these values in a new table.
I've tried
Test1 = differentiate(DailyGasDataTimeTable)
which gave the following error:
Error using Visualization: Differential test</a> (line 17</a>)
'differentiate' requires Curve Fitting Toolbox
and
Test2 = diff(DailyGasDataTimeTable)
which gave the following error:
Undefined function 'diff' for input arguments of type 'table'.
Error in Visualization: Differential test (line 17)
Unfortunately I'm stuck, please advise.
Kind regards,
Daniel

回答 (4 件)

Vinod
Vinod 2019 年 8 月 28 日
編集済み: Vinod 2019 年 8 月 28 日
You can extract the specific column, GasM3, from the timetable and use the diff function. Something like this:
data = thingSpeakRead(YourChannelNum,'OutputFormat','TimeTable');
deltaM3 = diff(data.GasM3);
newTable = timetable(data.Timestamps(2:end), deltaM3)
  2 件のコメント
Daniel Ubbink
Daniel Ubbink 2019 年 8 月 28 日
Dear Vinod,
Great, it works!
Thank you very much
Regards Daniel
Walter Roberson
Walter Roberson 2023 年 8 月 21 日
Note that it might make more sense to use gradient than diff

サインインしてコメントする。


Walter Roberson
Walter Roberson 2019 年 8 月 28 日
Use a timetable() object and use retime()

Kristina Collins
Kristina Collins 2020 年 8 月 31 日
What if my timetable is missing entries, or the entries are unevenly timed?

Olavo
Olavo 2023 年 8 月 21 日
編集済み: Walter Roberson 2023 年 8 月 21 日
Hello, Thanks for your answer it's very helpful!
What if I the variable I what to differentiate is not a fixed name and will be changing along the code? for example:
for i=1:10;
deltaM(i) = diff(data.GasM3{i}); % -->> does not work with this notation
end
  3 件のコメント
Steven Lord
Steven Lord 2023 年 8 月 21 日
Or you could use a numeric index.
T = array2table(magic(4))
T = 4×4 table
Var1 Var2 Var3 Var4 ____ ____ ____ ____ 16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1
A = T{:, 3} % Equivalent to T.Var3
A = 4×1
3 10 6 15
If you're release R2023a or later, you may be able to compute directly on the table or timetable, as described on this documentation page.
T2 = diff(T)
T2 = 3×4 table
Var1 Var2 Var3 Var4 ____ ____ ____ ____ -11 9 7 -5 4 -4 -4 4 -5 7 9 -11
Olavo
Olavo 2023 年 8 月 22 日
Thanks Walter and Steven, very useful information.
Just to add some extra information, I found the function wildcardPattern very useful to get similar names from table. would be something like:
varname = "GasM3" + wildcardPattern;

サインインしてコメントする。

コミュニティ

その他の回答  ThingSpeak コミュニティ

カテゴリ

Help Center および File ExchangeMATLAB Mobile Fundamentals についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by