MATLAB Answers

How to delete all rows made out of a certain vector/array/row values from a matrix?

1 view (last 30 days)
tban
tban on 10 Mar 2017
Commented: Guillaume on 10 Mar 2017
data=
[1 1 1 2 2 12;
2 18 5 5 5 5;
5 1 1 5 5 5;
4 11 13 2 2 12;
5 1 1 5 5 5]
... (2093 lines)
mode = [5 1 1 5 5 5]
I found a way to find the mode row. In this preview, it's [5 1 1 5 5 5]. How do I remove such rows from the matrix?

  0 Comments

Sign in to comment.

Answers (1)

Adam
Adam on 10 Mar 2017
data( idx, : ) = [];
will delete a row (or multiple rows), idx, from a matrix. Since you say you already have a way to find the row you want I assume this is all you are asking?

  5 Comments

Show 2 older comments
tban
tban on 10 Mar 2017
[uA,~,uIdx] = unique(activitydata_edited,'rows');
modeIdx = mode(uIdx); %mode convert implicit linear relationship to explicit input-output relation
modeRow = uA(modeIdx,:); %# rank #1
top10(1,:) = modeRow % just saving the vector before i delet it to recalculate
activitydata_edited(modeRow,:); %uncomment to see 6 vectors of [5 5 5 5 5 5] which is the mode
activitydata_edited(modeRow,:) = [] % length only changes by 1
i know, very frustrating I basically have a long list of vectors and i need to find which one is most used. I find 1st, record it, delete all of them. Find second, delete those too.... and so on. Need top 10 most used vectors.
Adam
Adam on 10 Mar 2017
I'm not really getting what is going on here and what exactly modeRow contains, e.g. this simple example works fine:
a = [1 1 1 1; 2 2 2 2; 3 3 3 3; 4 4 4 4; 5 5 5 5];
myIdx = [1 3];
a( myIdx,: )
a( myIdx,: ) = []
Guillaume
Guillaume on 10 Mar 2017
@Tudor, since uA is a column vector, uA(modeIdx, :) is the same as ua(modeIdx), and since modeIdx is scalar, ua(ModeIdx, :) is scalar. So modeRow is scalar, so it's totally expected that only one row is removed.
modeRow = uIdx == modeIdx;
would fix your problem.

Sign in to comment.