Removing a Range of Elements from an array

조회 수: 53 (최근 30일)
Hans123
Hans123 2019년 3월 28일
댓글: Hans123 2019년 3월 28일
Hi,
I have a matrix M and I am interested in the 12th column which has elements [1 2 3 4..... 540 589 760 761 770 47 46 47 48]
My goal is to get rid of all the elements after 750, including the values less than it.
My first code was
M(M(:,12)>750,:) =[];
but this didn't get rid of 47 46 48..
Mx= find(M(:,12)>750);
Mxmin=min(Mx); %to find the smallest value above 750 (in this case 760)
M(Mxmin:end,12)= [];
currently I am using this code, which gives me an error that says A null assignment can have only one non-colon index.
What am I doing wrong?
  댓글 수: 1
Hans123
Hans123 2019년 3월 28일
I want to eliminate the whole row of that matrix, if the column 12 contains a 760 - I want that row removed. That's why I used [ ]

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

채택된 답변

Walter Roberson
Walter Roberson 2019년 3월 28일
M(find(M:,12)>750,1):end, :) = [];
  댓글 수: 1
Hans123
Hans123 2019년 3월 28일
wow!
Thank you, really appreciate it

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

추가 답변 (1개)

Jos (10584)
Jos (10584) 2019년 3월 28일
ix = find(M(:,12) > 750, 1, 'first') % find the row index of the first element in the 12th column of A being larger than 750
M(ix:end,:) = [] % remove all the rows of M starting with this row

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by