I have two arrays which contain times. The first is the state of a device indicating when power was turned on and the second array is time stamps of the actual command issued to the device. See plot below:
The vertical dashed lines indicate power on commands and the blue line represents device state (1= on 0 = off).
What I want to do is create a matrix matching up commands to device responses. The trouble is that they are not 1 for 1. There are redundant commands and extra power cycles (from manual operations ect.). Ideally I would like to pair an un-commanded state change to a NaN in the command column and similarly any redundant commands or commands that don't result in a state change to a NaN in the state column. See sample data and desired output below:
indicatesOn = [1 2 3 4 5];
commandIssue = [1.9 2.8 2.9 4.8 4.9 5.1]
matchedOutput =
NaN 1.0000
1.9000 2.0000
2.8000 NaN
2.9000 3.0000
NaN 4.0000
4.8000 NaN
4.9000 5.0000
5.1000 NaN
So basically the Command times are in Column 1 and Power on is in Column 2. A NaN in the Command column would signify that there was not a preceding command to the change in state (manual operation of device). A NaN in the State/power-on column would signify that the device did not respond to that particular command (either already on or multiple commands were issued).
I started trying to sort this out and got into a mess of for loops and lots of if/else logic and thought there had to be a better way.
Any help is appreciated!
EDIT: