How to delete a column from a TimeSeries?

4 views (last 30 days)
Marlon Saveri Silva
Marlon Saveri Silva on 20 Apr 2019
Edited: dpb on 21 Apr 2019
Hello,
I would like to know how to delete a column from a TimeSeries.
I need to plot two curves in the same figure but different y-axis. First: time vs temperature; second: time vs level.
I got the temperature from a TimeSeries matrix called MyTimeSeries, whereas the level is in a datetime array. Unfortunatelly, when I try the code below, an error* appears in the add axis function.
plot(MyTimeSeries.Time, MyTimeSeries.Data(:,1)); hold on
addaxis(Time,Level);
So i use the follow code. However, it also plots data (:,2), (:,3), etc, and I need only Data(:,1). That's why I need to delete the other columns.
plot(MyTimeSeries); hold on
addaxis(Time,Level);
Well, I had tried to convert MyTimeSeries.Time and MyTimeSeries.Data to datetime values, but when I do it, the matrix is very strange, with strange numbers instead of time.
I also tried to convert Time and Level to a TimeSeries format, but when I do it, another error** appears, since some values in "Level" are N/A (because this is the way my controller works, it applies N/A for some conditions).
MyTimeSeries.Time format: '29-Mar-2019 09:40:15'
================================================================================
*Error:
Error using aa_splot (line 24)
Data inputs must match the axis configuration. A numeric axis must have numeric
data inputs or data inputs which can be converted to double.
Error in addaxis (line 135)
hplts = aa_splot(varargin{:});
**Other error:
Error using timeseries.tsChkTime (line 572)
Time vector must contain only finite values.
Error in timeseries/init (line 286)
time = timeseries.tsChkTime(time);
Error in timeseries (line 343)
this = init(this,varargin{:});
  3 Comments
Marlon Saveri Silva
Marlon Saveri Silva on 20 Apr 2019
dpb, thanks for answering. I've attached an example using part of the data.
dpb
dpb on 21 Apr 2019
Edited: dpb on 21 Apr 2019
The data into the time series is an array not as separate variables...so the answer to the acutal question as asked is "You can't" -- you can recreate the timeseries with just one column but it doesn't know about multiple variables as anything except columns in an array, unfortunately.
What are the two columns of data? Is that really a temperature? Temperature of what, in what units? (The last Q? really don't have bearing on the questions you raised, just that it looks odd enough that am curious what we're dealing with).
I've not use the timeseries object; it seems too limited and more trouble than it's worth in anything I've tried and I think you've run into the same issues...the plot function for the time series doesn't do anything but show the whole timeseries with no arguments for subsets of the data--what your plot statement does is to plot the actual numeric internal values of the timeseries NOT the actual times...I still haven't exactly figured out just what those represent; without the raw data that created the timeseries I've not been able to reproduce what those are and changing the format string or units doesn't seem to make any difference.
Try just
plot(MyTimeSeries)
to see the difference between what you did by plotting the variable against the numeric returned time versus what the builtin routine does that uses whatever internals are within the class. This penchant to hide stuff that user needs inside the class methods is why I've just never figured out a real use for the timeseries as it is presently implemented--it's "just not ready for prime time!" in my estimation.
All in all, I'd suggest throwing the timeseries away and use a regular table or just plain arrays/variables.
Post the data that created the timeseries itself and I'll show you what I'd do...
OK, the level array actually does contain NaN; that's ok; Matlab plotting functions will just ignore those values. But, you need some time data to go with it that matches up 1:1 with those values -- iow, where's the time the level data goes to?
To plot it so it looks like something, try--
isOK=isfinite(Level); % find the data values only
plot(Time(isOK),Level(isOK)) % plot only those values
If you plot the whole thing, all the NaN values will make for a broken line...

Sign in to comment.

Answers (0)

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!