How do I apply a sample time to an array of values that represent data points at different times?
7 views (last 30 days)
Show older comments
MathWorks Support Team
on 26 Jun 2019
Edited: MathWorks Support Team
on 31 Jan 2025
I have a table/array/matrix of values in the MATLAB workspace, representing data from sensors, each arranged in a column. The columns have different sample times, depending on the sensor, and I want to separate these columns so that I can have workspace variables that correspond to each sample rate. I also want to add that sampling rate so that the data points correspond to a specific time of measurement. How do I do this?
Accepted Answer
MathWorks Support Team
on 17 Jan 2025
Edited: MathWorks Support Team
on 31 Jan 2025
This is achievable in MATLAB with some commands to clean up our data first and then create a Timeseries Object. Assuming you have an array of real numbers of size 300x6 meaning you have 6 sensors and 300 data points for each, for example:
>> data = [rand(100,2) ; zeros(200,2)] >> data = [data, rand(300,4)];
First, you can select the columns with a specific sample rate, for example, the first 2:
>> dataAtSampleRate1 = data(:,1:2);
Then we can clean it up by noticing that many of the values of these columns are zero, meaning it was padded with non-existent data, so we can remove them. First, we find the first row where the padding starts:
>> [index, ~] = find(~dataAtSampleRate1,1)
Then we remove the data starting at that row:
>> dataAtSampleRate1(index:end,:) = [];
Now we need to create a Timeseries Object to specify a sample time for the data and assign times to each row:
>> ts = timeseries(dataAtSampleRate1)
Now we can double-click on the "ts" variable in the Workspace window, select "Uniform time vector" and add start and end times for the data collection. This will automatically calculate the measurement time for all the data points in "ts".
To obtain more information on manipulating Timeseries Objects, execute the following command in the MATLAB R2019b command window to view the release-specific documentation:
>> web(fullfile(docroot, 'matlab/data_analysis/time-series-objects.html'))
Please follow the below link to search for the required information regarding the current release:
0 Comments
More Answers (0)
See Also
Categories
Find more on Time Series Collections in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!