Timetables not fully supported by plot tools?

34 views (last 30 days)
Luca
Luca ongeveer 11 uur ago
Commented: dpb ongeveer 6 uur ago
Hello,
I am just wondering why when plotting a timetable with duration as time axis, The "basic fitting" and "data statistics" tool in plot windos are not available.
Does this mean that timetables have some limitations compared to arrays or tables? I am asking because I need to decide if timetable is the right data structure for my use case. Basically I am importing some measuremet datas from sensors acquisition which have timestamps. In the past I would have just used plain arrays, but I see that in modern Matlab timetables are somehow suggested for these use cases.

Accepted Answer

dpb
dpb ongeveer 6 uur ago
Moved: dpb ongeveer 6 uur ago
The issue isn't with the timetable itself but in the extensions added to the plotting figure haven't been updated to include them. Never using those, I hadn't noticed .. I don't suppose the regular table is available, either.
There are some features such as retime that are only available with timetables that does make them handy for coding with, but if the interaction with the plot itself is a required feature, you'll have to use some other mechanism or extract the data from the timetable prior to plotting.
Would seem worthy of submitting an enhancement request...
  2 Comments
Luca
Luca 1 minuut ago
Thanks a lot for your answer.
No, indeed I don't need this feature but I was just wondering if there are general limitations in the usage of timetables compared to matrix/arrays.
Do you think that representing time domain signals is a "correct" usage of timetables? Take into account that I will probly need to use them as input in Simulink as well.
Thanks in advance
dpb
dpb ongeveer 3 uur ago
"...[is] representing time domain signals is a "correct" usage of timetables?"
Well, given a timetable is a set of times with associated data to go with the observations, it appears intended to be used for precisely such things.
I would say it is more a question of what one intends to do with the data; if features specifically implemented for the timetable data class such as retime mentioned before would be helpful it would seem a reasonable fit.
OTOH, if we're talking about highspeed signal processing data acquisition kinds of application, it is probably not the ideal use case. There is another timeseries data class intended for sampled data although I've not found it convenient for my usage; there are features in it that may be of interest for certain tasks.
As for using with Simulink, I don't know a thing about it -- I'd guess interaction there would probably be simpler with simple arrays, but again I suspect it may matter as to what interaction is needed.

Sign in to comment.

More Answers (1)

Steven Lord
Steven Lord ongeveer 4 uur ago
Let's say that with basic fitting, you wanted to fit a quadratic (y = a(1)*x^2+a(2)*x+a(3)) to your data. If the x data was double, this would be possible.
v = 0:5
v = 1×6
0 1 2 3 4 5
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
y = polyval([1 2 3], v) % a would be [1 2 3]
y = 1×6
3 6 11 18 27 38
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
A = polyfit(v, y, 2) % check that it is [1 2 3]
A = 1×3
1.0000 2.0000 3.0000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
But with duration data for x, let's do a unit analysis. How would you add x^2 (with units of hours squared), x (with units of hours), and a constant together? I suppose you could make the constant a(1) be unitless, a(2) have units of hours, and a(3) have units of hours squared (which would require y to have units of hours squared) but then you couldn't store them all in one array.
In fact, the power operators aren't defined for duration data. Neither is the times operator where both operands are duration arrays. We don't let you make duration data with units of hours squared.
x = hours(v)
x = 1×6 duration array
0 hr 1 hr 2 hr 3 hr 4 hr 5 hr
try
z = x.^2
catch ME
fprintf("Error: %s", ME.message)
end
Error: Invalid data type. Argument must be numeric, char, or logical.
x2 = hours([1 2; 3 4]);
try
z = x2^2
catch ME
fprintf("Error: %s", ME.message)
end
Error: Undefined function 'double' for input arguments of type 'duration'. To convert from durations to numeric, use the SECONDS, MINUTES, HOURS, DAYS, or YEARS functions.
try
z = x.*x
catch ME
fprintf("Error: %s", ME.message)
end
Error: Multiplication is not defined between two duration arrays.
So IMO it doesn't conceptually make sense to do basic fitting with date and time data.
The data statistics functionality could probably work with duration data. I haven't thought it completely through to identify any sticking points. My guess is that there haven't been (very many if any) requests for that tool to support datetime and duration data, so it hasn't been a priority.
  4 Comments
dpb
dpb ongeveer 3 uur ago
I posted some thoughts on that topic above -- I agree that if it is classic signal processing, particularly with fixed-rate sampling the array is likely a better choice although as noted there, there is the specific timeseries data class as well although it seems oriented towards events handling.
dpb
dpb 17 minuten ago
ADDENDUM:
The comment by @Steven Lord regarding the units being messy is certainly true for displaying durations in anything other than powers of some fractional unit; the digital represntation in hh:mm:ss.SSS notation is probably simply not feasible for powers.
To do a duration would mean a conversion to a represntative numeric form and then retaining the associated powers of the one chosen unit as in the examples above are in years, years^2.

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!