Using "unique" in Matlab, keeping the first appearance

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 remove the duplicate string 'on', but also the string "off" because it is redundant and starting with "off" is bad for my script.

It seems that the β€œfirst” argument with a unique one should help, but I have no joy.

Any suggestions?

+3
source share
1 answer

"rows" "first", 'on'. "", 'on', .

A = [50 1 70; 50 0 70; 50 1 70]
A =

    50     1    70
    50     0    70
    50     1    70

A(:,2) = 1 %Set all on/off values to 'on'

A =

    50     1    70
    50     1    70
    50     1    70

R = unique(A,'rows')

R =

    50     1    70

EDIT: "off" , , . , Nx3

rows = 2:length(A)-1;
p=find(all(A(rows+1,:)==A(rows-1,:),2)); %Get index of where rows are equal
A(rows(p),2) = 1; Set those rows to be 'on', so they can be removed by unique
+2

All Articles