Effacer les filtres
Effacer les filtres

How to delete cell entries with an index vector

15 vues (au cours des 30 derniers jours)
Melanie
Melanie le 10 Jan 2014
Commenté : Simon le 13 Jan 2014
Dear community,
I have a cell
A=cell(m,n)
and a logical vector
b=(m,1)
containing logical ones and zeros (true, false). What I like to do now is to delete the cell entries, if there is a logical one
A(b,:)=[];
But the error is: Index of element to remove exceeds matrix dimensions. What have I done wrong?
Thanks a lot!

Réponses (3)

Azzi Abdelmalek
Azzi Abdelmalek le 10 Jan 2014
n=3;
m=6;
A=num2cell(rand(m,n))
idx=[1 0 0 1 1 0]
A(logical(idx),:)=[]

Simon
Simon le 10 Jan 2014
Hi!
Are you sure that b is not longer than size(1) of A? Is b really a logical vector with true or false? I have no problem if I use
n=3
m=5
A=cell(m,n)
b=false(m,1)
b(2) = true
b(5) = true
A(b,:)=[]
An error is thrown for
A=cell(m,n)
b(6) = true
A(b,:)=[]

Melanie
Melanie le 13 Jan 2014
Thanks for your answers, I still have the error code:
Index of element to remove exceeds
matrix dimensions.
I checked the sizes now for 100 times :D I don't know what could help me, m is always the same.
BR, MS
  1 commentaire
Simon
Simon le 13 Jan 2014
I'm wondering where your error message comes from. If I use my example above the message is
Matrix index is out of range for deletion.
Tested on Matlab R2010b. Maybe we use different versions or the problem is different ...

Connectez-vous pour commenter.

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by