delete repeated data in matlab

To delete repeated data in Matlab, you can use the unique function. Here is an example:

Suppose you have a vector x:

main.m
x = [1, 2, 5, 2, 3, 1, 4, 5, 6];
33 chars
2 lines

To get a new vector with repeated elements removed, simply call the unique function:

main.m
y = unique(x);
15 chars
2 lines

The resulting vector y is:

main.m
y = [1, 2, 3, 4, 5, 6];
24 chars
2 lines

Note that the order of elements in y may be different from that in x.

related categories

gistlibby LogSnag