필터 지우기
필터 지우기

how to extract matrix based on a condition?

조회 수: 10 (최근 30일)
MAHMOUD ALZIOUD
MAHMOUD ALZIOUD 2017년 11월 2일
댓글: MAHMOUD ALZIOUD 2017년 11월 3일
Hello Everyone, if I have a matrix for example 100 rows by 38 columns, column number 14 has distances, how can i build a for loop with a condition saying: if the distance is between 8 and 12 ft then take the rows corresponding to this condition to construct a new matrix, and put zeros instead of them in the main matrix. i need to do this because i need to stay away from duplicate data when i run another condition. HELP PLEASE

채택된 답변

KSSV
KSSV 2017년 11월 3일
You need not to use a loop, you can use the below lines of code to get what you want.
A = randi(100,38) ; % some random data
distance = A(:,14) ;
%%apply condition to get rows indices satifying the condition
idx = find(distance > 8 & distance < 12)
  댓글 수: 1
MAHMOUD ALZIOUD
MAHMOUD ALZIOUD 2017년 11월 3일
Thank you KSSV for this, now when I take the data by this condition, how can I leave the rows zeros in the original matrix after I take them?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by