Gloria
Gloria

Reputation: 329

how to detect the repeated values in a vector in matlab

If I have these data: m= {'a' 'b' 'a' 'v'}

how to make an if statement that if I have a repeated values in the row, I should omit this row I have this code but it is not a direct code... I want something more profisional (one line function without for loop !!)

for j=1:length(m)
    if isequal(m{1,j},m{1,j+1})
        disp('error');
    end
end

Upvotes: 1

Views: 6784

Answers (1)

Matti Pastell
Matti Pastell

Reputation: 9283

Use the unique command. It can also find repeated rows from a matrix http://www.mathworks.se/help/matlab/ref/unique.html#btb0_85

Upvotes: 4

Related Questions