April 2, 2018
I'm having trouble trying to develop a function for comparing the data points I have collected from my light intensity sensor in order to see the period of time when there is the lowest activity of light. I'm not familiar with programming so I appreciate all the help I can get. Essentially, I have a light intensity sensor measuring the quality of light in a room which will be uploaded onto the ThingSpeaks server. So far I have been able to retrieve data points in a table format using under the Matlab Analysis App,
readings = thingSpeakRead(ChannelID, 'Fields', 1,'NumPoints', 60, 'OutputFormat', 'table')
However, I want to create a function that can see when the light quality value is low for a few occurrences, mark that time and then subtract it from the next time the light quality is at a higher value to figure out the longest time that the light level stays low. I am unsure about how to do this using the above function to retrieve the data thus far. My general idea is to find the first low value with the corresponding time, search through the rest of the data until a high value is present again with the corresponding time and then subtract both times under a table format. Ultimately, I want to use this data as a proxy to see how much light impacts me when I sleep by using light quality as a factor.
Does anyone have an idea of how this can be implemented or is there an easier way for me to obtain the results I want?
March 7, 2017
Neat project. I wonder what you are using to measure light level. In phase II of the experiment you could measure the spectrum too.
I would set up a timeControl that runs a MATLAB analysis daily, then writes your new values to another channel.
There is presently a code template called "Replace missing values in data" that will show you some of these techniques.
Use thingSpeakRead() to get the data, you can use 'numDays', 1 or 'NumMinutes', 600 depending on when you set up the TimeControl and how long you sleep.
If you know the threshold for high and low data, you can use the find() function to separate the data.
If your channel writes occur at regular intervals, then the length of each index array will be proportional to the relative light and dark times.
Then you can write the data to your other channel for later study.
thingSpeakWrite(otherChID,'writeKey','XXXXXXXXXXXXXXXX','fields',[1 2], 'values',[length(lowIndex) length(highIndex)]);
If you want to calculate each duration separately, you can loop through the timetable that you read in the analysis and add to the duration until the index array is non continuous. ... if(lowIndex(i)+1==lowIndex(i+1))..add duration...
Most Users Ever Online: 166
Currently Browsing this Page:
Guest Posters: 1
Newest Members:Team_mafia, icXu, emorphistechno, VTVMART, manimozhi, adamhebrew
Moderators: cstapels: 460
Administrators: Hans: 405, lee: 457