EDIT - file now attached, apologies.
Hi,
Noob question about data import from .csv file.
Got a historian database that logs values of various sensors. Can export from database to flat file.
Typical format of file: TagName,DateTime,Value. Where there are multiple tagnames in each file, values usually recorded every second. Sample file attached.
Aim is to plot sensor values on same plot and then do some frequency analysis to determine periodicity patterns.
So far I have been pre-processing by manually splitting sensor data into individual files (using Excel) then importing these files and plotting. I feel there must be more efficient method/workflow to read this mixed file. (I did see timeseries mentioned in data analysis section of documentation maybe this is way to go, but can't figure out how to create from file.)
  • Can any one suggest a suitable workflow with required commands/wizard?
Any help or info appreciated.
Thank you,
Michael

3 comentarios

Walter Roberson
Walter Roberson el 25 de Ag. de 2015
The sample file did not get attached.
Walter Roberson
Walter Roberson el 25 de Ag. de 2015
Do the "TagName" identify the different sensors? Is the data from all of the files to be combined, or is each file to be handled independently?
Michael Cody
Michael Cody el 25 de Ag. de 2015
Sample file now attached.
Yes TagName is ID of sensor. Mixed, current, torque, speed.
Looking for elegant way to import and then plot all or any combination on same plot. Then further analysis on selected sensors: basic stats and identifying periodicity of reading.

Iniciar sesión para comentar.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 25 de Ag. de 2015
Consider using readtable() . Then you can use http://www.mathworks.com/help/stats/grpstats.html for grouped statistics
If you have the data in Tags (cell array of strings) then you can determine the grouping information by using
[uniquesensors, ~, sensornumber] = unique(Tags);
After that, sensornumber(K) tells you which grouping is appropriate for Tags{K}, so for example:
numsensors = length(uniquesensors);
for Sn = 1 : numsensors
matches_sensor = sensornumber == Sn;
times_for_sensor = DateTime(matches_sensor);
vals_for_sensor = Value(matches_sensor);
ph(Sn) = plot(times_for_sensor, vals_for_sensor); %assuming times are datenum or datetime not strings
if Sn == 1; hold all; end
end
legend(ph, uniquesensors);

6 comentarios

Michael Cody
Michael Cody el 25 de Ag. de 2015
Thanks Walter. readtable looks way to go and I will explore grpstats.
Just one other clarification for noob like me, can you explain the tilda notation in your example? [uniquesensors, ~, sensornumber]
Michael
Andy
Andy el 25 de Ag. de 2015
The ~ is a dummy for an output which isn't needed. In this instance unique has up to four outputs, you only need the first and the third. You could use a variable name for the second but as you do not require it for further processing simply using the ~ allows you to access the third output but ignore the second.
Michael Cody
Michael Cody el 25 de Ag. de 2015
Great. Thanks Andy
Michael Cody
Michael Cody el 25 de Ag. de 2015
One problem I running into is format timestamps to date using readtable. I can read in as string, but would like to have a datetime/datenum format.
I think something like below should work, but fails
T = readtable('20150430_2250_2300.csv','Format','%s%{MM/dd/yyyy HH:mm:ss}D%f')
Error using textscan Badly formed format string.
Can anyone suggest a correct format?
Sample line of .csv file:
IT_73221.Value,4/30/2015 10:50:00 PM,36.430000305175781
Thanks
If you happen to be using R2013b or R2014a, then those support readtable() but textscan for them does not support %{}D date format; that was introduced in R2014b I think (might have been R2015a). The workaround for those is to read the field with %s and datenum() as needed. You could use
T.DateNum = datenum(T.DateTime, 'MM/dd/yyyy HH:mm:s');
Michael Cody
Michael Cody el 26 de Ag. de 2015
Walter, Thanks a lot again. Yes I running R2014a, so that explains it. Michael

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Preguntada:

el 24 de Ag. de 2015

Comentada:

el 26 de Ag. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by