Delete rows of a matrix

14 views (last 30 days)
sofia
sofia on 13 Jan 2014
Answered: Amit on 13 Jan 2014
This is a portion of the matrix :
8 9 10 12
5 4 3 2
10 8 6 4
As you can see that row number three : [10 8 6 4] is row numbre two *2, I want their to be only one row. general, if a row1 in matix have a relation with other row2 : row1=row2*k then delete just one row of them: row1 or row2.
So I want the output to be like:
8 9 10 12
5 4 3 2
  1 Comment
dpb
dpb on 13 Jan 2014
Basically have to compute the pairwise logical of
all(fix(x(i,:)./x(j,:))==x(i,:)./x(j,:))
over unique combinations of i and j then remove those for which result is true.

Sign in to comment.

Answers (2)

Azzi Abdelmalek
Azzi Abdelmalek on 13 Jan 2014
Try this
A=[8 9 10 12
5 4 3 2
10 8 6 4]
m=rank(A);
n=size(A,1);
k=0;
idx=[];
while k<n-1 & numel(idx)<n-m
k=k+1
if isempty(intersect(k,idx))
ii=bsxfun(@ldivide,A(k+1:n,:),A(k,:));
idx=[idx ;find(all(bsxfun(@eq,ii,ii(:,1)),2))+k];
end
end
A(idx,:)=[]

Amit
Amit on 13 Jan 2014
Lets say you matrix is something named A.
Tol = 1e-6;
count = 1;
flag = 1;
while (flag == 1)
temp1 = A(count+1:end,1)/A(count,1);
temp2 = (bsxfun(@minus,bsxfun(@rdivide,A(count+1:end,:),temp1),A(count,:))).^2;
temp3 = [zeros(count,1); sum(temp2,2)<Tol];
A(find(temp3),:) = [];
[m,~] = size(A);
if (m == count)
flag = 0;
end
count = count + 1;
end

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!