using 'unique' in Matlab, preserving first occurence -


Hello everyone I have data that sometimes looks like this: time ... on / off. Value
50 ...... 1 ......... 70
50 ...... 0 ......... 70
50 .. ... 1 ......... 70

I want to delete the duplicate 'on' line, but also the 'off' line because it is redundant, and a 'close' my Bad for the script.

It seems that with the unique 'first' logic should help, but I have no happiness.

Any suggestions? Use unique with 'rows' logic instead of 'first' to remove duplicates 'on'.

To remove 'off', a simple solution is to first set everyone to 'on', and then to uniquely Use A = [50 1 70; 50 0 70; 50 1 70] A = 50 1 70 50 0 70 50 1 70A (:, 2) = 1% Set the value to all / off 'A' on A = 50 1 70 50 1 70 50 1 70 R = Unique ( A, 'rows') R = 50 1 70

EDIT: To remove the 'closed' line, only when two neighboring rows are the same, you have to compare the neighboring rows. There are several ways to do this, but I have quickly created a general Nx3 matrix here

  rows = 2: length (A) -1; P = seems (all (A (rows + 1, :) == A (rows -1, :), 2)); Get the index of% where rows are equal (rows (p), 2) = 1; Set those lines to 'On', so that they can be deleted by a unique    .

Comments