To control a thermostat in matlab, we need to use control system toolbox. First, design a controller to generate the output required to reduce the error signal between the desired temperature and the actual temperature. Then write a script that reads in data representing the desired temperature and the actual temperature, and uses the controller to output the necessary setting for the thermostat.
Here's an example code:
main.m625 chars27 lines
This code reads in data representing the desired temperature and the actual temperature, and creates a PID controller that minimizes the error between the two. It then simulates the controller over time, generating an output that represents the necessary setting for the thermostat, and plots the results.
Alternatively, if you just want to obtain the temperature value in a corresponding time from a vector of temperatures, you can do:
main.m284 chars12 lines
This code reads in temperature data and a desired time, finds the index of the closest time in the data, and returns the temperature at that time.
gistlibby LogSnag