필터 지우기
필터 지우기

how to extract rows and leave zeros behind?

조회 수: 3 (최근 30일)
MAHMOUD ALZIOUD
MAHMOUD ALZIOUD 2017년 11월 11일
댓글: MAHMOUD ALZIOUD 2017년 11월 11일
Dear All, I have a big matrix called A, I extract another matrix from this A and call it B based on a condition of the value x in the matrix A, I wrote this code but it doesnt work well, can any body please help fix it? I need to extract the new matrix B and leave the rows as zeros in the original matrix A.
B= A(x(:,1)>9.84 & x(:,1)<12.47 , :);
A(find(A(B,:)))=0;

채택된 답변

Walter Roberson
Walter Roberson 2017년 11월 11일
B= A(x(:,1)>9.84 & x(:,1)<12.47 , :);
leaves B as a subset of A, having selected some of the rows but retaining all columns.
A(B,:)
then uses that subset as an index into A. That is mostly going to fail as the entries are probably not zero.
Try
mask = x(:,1)>9.84 & x(:,1)<12.47;
B = A(mask, :);
A(mask, :) = 0;
  댓글 수: 1
MAHMOUD ALZIOUD
MAHMOUD ALZIOUD 2017년 11월 11일
Ok Mr Walter I will give it a try, this looks very correct and simple. Thank you very much

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by