Plotting acceleration vs time on Matlab from accelerometer data that doesn't have a time column

조회 수: 10 (최근 30일)
Hello, I would like to plot x y and z axes of acceleration versus time from the csv file that was outputted from my sensor, the first two rows of the data of the csv file give the timestamp and the frequency of the reading therefore they should not be read by matlab and the columns represent x y and z axes respectively. The problem I am having is that the file does not have a time column and that I need to create an abstract one so that I could plot the acceleration vs time (or do I actually need one? is there a command that I can just use?) Thank you very much in advance!!
  댓글 수: 3
Adviye Irem Yuceel
Adviye Irem Yuceel 2021년 6월 7일
There are no timestamps unfortunetly, there is only one timestamp that gives the time data collection started and then the data is sampled at 32 Hz
Adviye Irem Yuceel
Adviye Irem Yuceel 2021년 6월 7일
The format of the given one timestamp is in unix or seconds from 1-1-1970 in UTC

댓글을 달려면 로그인하십시오.

답변 (2개)

Mathieu NOE
Mathieu NOE 2021년 6월 8일
hello
as we know the sampling rate Fs and the amount of samples , there is no big difficulty to reconstruct a time vector :
samples = length(data);
dt = 1/Fs;
time_vector = (0:samples-1)*dt

Duncan Po
Duncan Po 2021년 6월 8일
You can create a timetable, and just supply the start time and frequency. Timetable will compute the timestamps for your data. For example,
>> data = (1:10)';
>> starttime = datetime('now');
>> fs = 2; % 2Hz in this example
>> tt = timetable(data, 'StartTime', starttime, 'SampleRate', fs)
tt =
10×1 timetable
Time data
____________________ ____
08-Jun-2021 14:59:30 1
08-Jun-2021 14:59:30 2
08-Jun-2021 14:59:31 3
08-Jun-2021 14:59:31 4
08-Jun-2021 14:59:32 5
08-Jun-2021 14:59:32 6
08-Jun-2021 14:59:33 7
08-Jun-2021 14:59:33 8
08-Jun-2021 14:59:34 9
08-Jun-2021 14:59:34 10
You can then either plot directly using stackedplot, or extract the timestamps using tt.Time, and then call plot.
  댓글 수: 2
Adviye Irem Yuceel
Adviye Irem Yuceel 2021년 6월 8일
I get this error message (some of my data values are negative because the sensor gives the opposite acceleration in negative):
Error using stackedplot (line 71)
Expected vars to be positive.
Error in stress (line 32)
stackedplot(tt,y)
Is there a way to get arround this? Also can I start the starttime from the time stamp given in the csv file with the data in unix format?
Duncan Po
Duncan Po 2021년 6월 9일
To plot the timetable using stackedplot, you can simply pass in the timetable as the only input:
stackedplot(tt)
The error you encountered is due to the second input y. Apparently y is not a valid second input.
For unix time, there is a way to convert using the datetime function:
starttime = datetime(t, 'ConvertFrom','posixTime');

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by