How to get the delete rows with conditions and get the corresponding row number?

조회 수: 1 (최근 30일)
I have a matrix A, which is 1764 by 1023. But I need delete rows that meet this condition: the ratio between the 1 column and 2 column less than or equal to 1. Then I need to know all row numbers that I have deleted from the A. I get the new matrix B but I cannot get the row number. Can anybody please help me? Here is the code I wrote:
A = [1 2 3
11 1 46
45 45 12
47 24 5
25 14 3];
col_1 = 1;
col_2 = 2;
for i=size(A,1):-1:1
Ratio(i) = A(i,col_1)/A(i,col_2);
if Ratio(i) <= 1
A(i,:)=[];
[rows,cols] = find(Ratio(i) <= 1);
end
end

채택된 답변

Cris LaPierre
Cris LaPierre 2021년 3월 23일
Use a logical array (Ch 12 MATLAB Onramp) instead of a for loop.
A = [1 2 3
11 1 46
45 45 12
47 24 5
25 14 3];
% determine rows to delete
ind = A(:,1)./A(:,2) <= 1;
rows = 1:size(A,1);
rows = rows(ind)
rows = 1×2
1 3
A(ind,:)=[]
A = 3×3
11 1 46 47 24 5 25 14 3

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by