Logging average of data


amswitch

Recommended Posts

I've set up my program to log 10 seconds of data (i.e. input voltage and output voltage) in the following sequence:

while(1)
   wait(5)
   beginLogging(station7)
   wait(10)
   endLogging(station7)
   wait(5)
endwhile

But instead of logging each data point, I'm trying to just have the average value be logged.  Under "Event" for my output voltage (output7) channel,  I wrote:

Logging.station7.AddValue("Average", Mean((input-output) [0,9]))

Then I manually added "Average" as a channel for my "station7" logging set.  When I checked the .csv file I saved under "station7", nothing was logged.

Is there another way of logging the average value for a channel?

Link to comment
Share on other sites

You really should consider skipping logging sets and use the File. functions to do the logging yourself.  Then you can log whatever you want, whenever you want, in whatever format you want.  You'll basically want to use the File.Open(), file.write() and file.close() functions along with some string manipulation to create the string you write.  Something like:

while(1)
   wait(5)
   try
      file.open("myLogFile.csv", 0, 1, 1, 1)
      file.write(formatDateTime("%c", systime()) + "," + mean(input[0,9]-output[0,9]))
      file.close()
   catch()
      ? strLastError
   endcatch
endwhile

Note that I moved the [0,9] to right after the channels.  This is much more efficient than doing the difference between input and output without [] which will do the entire history, then subsetting to 10 values, then doing the mean.

Link to comment
Share on other sites

  • 1 year later...
El 19/8/2016 a la 1:24 PM, AzeoTech dijo:

Realmente debería considerar omitir los conjuntos de registros y usar el Archivo. funciones para hacer el registro usted mismo. Luego puede registrar lo que quiera, cuando quiera, en el formato que desee. Básicamente, querrá utilizar las funciones File.Open (), file.write () y file.close () junto con algunas manipulaciones de cadenas para crear la cadena que escriba. Algo como:

mientras (1)
   espere (5)
   intente
      file.open ("myLogFile.csv", 0, 1, 1, 1)
      file.write (formatDateTime ("% c", systime ()) + "," + mean (entrada [0,9] -output [0,9]))
      file.close ()
   catch ()
      ? strLastError
   endcatch
endwhile

Tenga en cuenta que mover el [0,9] a la derecha después de los canales. Esto es mucho más eficiente que hacer la diferencia entre entrada y salida, luego subconjuntos a 10 valores, y luego haciendo la media.

para sacar el promedio de un canal y despues exportar ese promedio en archivo excel le agradeseria su ayuda mucho

Link to comment
Share on other sites

"to get the average of a channel and then export that average in excel file would like your help a lot"

If you are going to use a logging set, you can just mark the Channel for averaging and then log that channel.  In the Channel setup, there is a column that says "Avg?"  Select that, then in the # Avg, select the number of data points you wish to average.  So, for example, if you are taking data once a second, and you enable averaging with a # Avg of 10, you would end up getting a data point every 10 seconds which is the average of 10 readings.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.