Index of element to remove exceeds matrix dimensions??!

2 ビュー (過去 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 Center および File ExchangeMatrix Indexing についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by