Message Boards Message Boards

Create a Plot of time versus data from a csv file?

Posted 7 years ago

I have a csv file I am reading and extracting the second column which indicates time

lengthofdataSample=200;
startofdatasample =100;

as follows:

time=Interpreter["Time"][Take[Import["STsensortrial.csvaa"],{startofdatasample,lengthofdataSample}][[All,2]]];

(and the 13th column which has my acceleration in X direction)

accX=Take[Import["STsensortrial.csvaa"],{startofdatasample,lengthofdataSample}][[All,13]];

I simply want to plot acceleration versus time to start with. but I am unable to find appropriate function or syntax to make this work. Last thing I tried was:

LinePlot[Transpose@{time,accX}]

but it only lists the data sets and does not plot.

I also wanted to plot two series, accX data and its moving average on one graph. But I do not see this working either.

ListLinePlot[Table[accX,MovingAverage[accX,50]]] 

Appreciate help for this newbie to Wolfram.

POSTED BY: E W
3 Replies
Posted 7 years ago

Thank you, Neil. Very helpful

POSTED BY: E W

Also as to MovingAverage, Table is the wrong thing -- it is for creating lists.

Do

ListLinePlot[{col3, MovingAverage[col3, 2]}]

You give ListLinePlot a list of data to plot (each one is a separate curve). In this case col3 and its MovingAverage.

POSTED BY: Neil Singer

If you want to Plot with TimeObjects you need to create a TimeSeries

ts = TimeSeries[Transpose[{time, data}]]

you may also find that plotting with DateListPlot[ts] will look better on a timeseries.

The other option is to not interpret your times as TimeObjects and plot them as numbers but I do not know the form of the time values in your file so I can't make any suggestion on how to do this.

Also your code would be simpler if you do something like this (leaving some of your details out):

alldata = Import["file","CSV"]
col1 = alldata[[startofdata ;; endofdata, 1]]
col3 = alldata[[startofdata ;; endofdata, 3]]

This takes rows starofdata through endofdata and column 1 (or 3)

Regards

POSTED BY: Neil Singer
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract