Indexing a cell array according to another cell array
Mostrar comentarios más antiguos
So I have two cell arrays, each represent onset and offset times of events, so they have the same size and they correspond to each other, for example:
A = {[2,3,4],[3,6],[5,7,9,10]};
B = {[2.5,4.2,4.7],[3.2,7.4],[6.2,7.6,9.4,11.3]}
I now was able to delete certain entries in A according to a different indexing vector c,let's say new A is (anything equals to 3 or between 7 to 9 is deleted):
A = {[2,4],[6],[5,10]}
How do I delete the corresponding entries in B? I want to achieve:
B = {[2.5,4.7],[7.4],[6.2,11.3]}
In other words delete the second, first, and second and third entires in the three cells in B. I tried to do it after entries were deleted from A, but the sizes and entries no longer match. It seems I have to somehow index A and B at the beginning before I mess with A, but I am not sure how to do this...
Respuesta aceptada
Más respuestas (1)
Azzi Abdelmalek
el 24 de Mzo. de 2016
A = {[2,3,4],[3,6],[5,7,9,10]};
B = {[2.5,4.2,4.7],[3.2,7.4],[6.2,7.6,9.4,11.3]}
idx=cellfun(@(x) x~=3 & ~(x<=9 & x>=7),A,'un',0)
C1=cellfun(@(x,y) x(y),A,idx,'un',0)
C2=cellfun(@(x,y) x(y),B,idx,'un',0)
celldisp(C1)
celldisp(C2)
10 comentarios
alicia che
el 1 de Abr. de 2016
Azzi Abdelmalek
el 1 de Abr. de 2016
idx for what?
alicia che
el 1 de Abr. de 2016
Azzi Abdelmalek
el 1 de Abr. de 2016
And how to apply C to your cell array?
alicia che
el 4 de Abr. de 2016
Editada: Azzi Abdelmalek
el 4 de Abr. de 2016
Azzi Abdelmalek
el 4 de Abr. de 2016
C does not contain 10 element but 12.
alicia che
el 4 de Abr. de 2016
Azzi Abdelmalek
el 4 de Abr. de 2016
Ok, but A contains just 9 elements!
alicia che
el 5 de Abr. de 2016
Azzi Abdelmalek
el 5 de Abr. de 2016
To make your question clear, post an example and explain clearly what you want, and post the expected result
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!