Note that there are some explanatory texts on larger screens.

plurals
  1. POSort / Match two columns of times padding with NaN
    text
    copied!<p>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: <img src="https://i.stack.imgur.com/9IGXy.jpg" alt="enter image description here"></p> <p>The vertical dashed lines indicate power on commands and the blue line represents device state (1= on 0 = off).</p> <p>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:</p> <pre><code>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 </code></pre> <p>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).</p> <p>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.</p> <p>Any help is appreciated!</p> <p>EDIT:</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload