Borrar filtros
Borrar filtros

Index of element to remove exceeds matrix dimensions??!

1 visualización (últimos 30 días)
Mariam Sheha
Mariam Sheha el 28 de Mayo de 2016
Comentada: Mariam Sheha el 28 de Mayo de 2016
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

Respuesta aceptada

Matt J
Matt J el 28 de Mayo de 2016
Editada: Matt J el 28 de Mayo de 2016
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 comentarios
Matt J
Matt J el 28 de Mayo de 2016
Editada: Matt J el 28 de Mayo de 2016
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 el 28 de Mayo de 2016
It is brilliant , i thought i have to enter it in the loop,
it works and i am very thankful for your precious help :)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by