andybdjuk Posted April 2, 2009 Share Posted April 2, 2009 Hi Guru, by now you will know my math is poor!! I would like to measure the slope of a graph displaying temperature against time for the previous hour and then display it as a variable (Degrees centigrade change/ Hour) until updated an hour later. As a nicety also hold the maximum change for a 24 hour period starting at midnight.. Can you give me any pointers as to how I would achieve this? Thanks Andy Link to comment Share on other sites More sharing options...
AzeoTech Posted April 2, 2009 Share Posted April 2, 2009 Well, you won't be able to do it directly in the graph, at least not automated, because the graph doesn't have any real script (unless you put it in the OnPaint event). So, I'd use the event of the channel for the trace of your graph. Here, you'll need to capture everything. First, you'll need a startup sequence to init the variables: global maxslope = -1e99 global lastslope = 0 global lastval = -1e99 Then in the event it'll be something like this (and I'm doing it off the top of my head, so you may need to check the docs on formatdatetime()): if (formatdatetime("%H",mychannel.time[0]) != (formatdatetime("%H",mychannel.time[1])) if (lastval == -1e99) lastval = mychannel[0] return endif lastslope = (mychannel[0] - lastval) / (mychannel.time[0] - gettime(lastval)) lastval = mychannel[0] if (lastslope > maxslope) maxslope = lastslope endif endif if (formatdatetime("%d",mychannel.time[0]) != (formatdatetime("%d",mychannel.time[1])) maxslope = lastslope endif Note that this doesn't take into account any noise in the signal. Its not doing a linear fit and getting the slope, its just looking at the slope between two points separated by about an hour. Link to comment Share on other sites More sharing options...
andybdjuk Posted April 2, 2009 Author Share Posted April 2, 2009 As always Guru, thank you for your time, I'm off to play. Andy Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.