필터 지우기
필터 지우기

Index of element to remove exceeds matrix dimensions??!

조회 수: 1 (최근 30일)
Mariam Sheha
Mariam Sheha 2016년 5월 28일
댓글: Mariam Sheha 2016년 5월 28일
Hello Everybody; i am having a problem with that code, regarding that i want to discards the columns with value less than 3...but it always gives me Index of element to remove exceeds matrix dimensions
can you please help me through that?!
[orderedCount, SortOrder]=sort(Count,'descend');
Items=Items(SortOrder);
%%%the propabilty of presence of each
for i=1:length(orderedCount)
if(orderedCount(i)<3)
items(i)=[];
end
end

채택된 답변

Matt J
Matt J 2016년 5월 28일
편집: Matt J 2016년 5월 28일
Looping will not work because the length and indexing of "Items" changes each time you remove an element. You must remove all of the elements simultaneously,
Items(orderedCount<3)=[];
  댓글 수: 5
Matt J
Matt J 2016년 5월 28일
편집: Matt J 2016년 5월 28일
As I mentioned, and as my example showed you, this should be done without a loop. The single line
Items(orderedCount<3)=[];
will do the whole job.
Mariam Sheha
Mariam Sheha 2016년 5월 28일
It is brilliant , i thought i have to enter it in the loop,
it works and i am very thankful for your precious help :)

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

추가 답변 (0개)

카테고리

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