Delete rows of a matrix
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commento
dpb
il 13 Gen 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.
Risposte (2)
Azzi Abdelmalek
il 13 Gen 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,:)=[]
0 Commenti
Amit
il 13 Gen 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
0 Commenti
Vedere anche
Categorie
Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!