intersection of two tables question

Hello,
I have 2 cell arrays of the following form:
A = {1,2,3;'a','b','c';'e','f','g'};
B = {'x','y';[],[];'z','v'};
and I want to create a third cell array with the content of A, but with only those rows that are not empty in B. What is the most efficient way to do that?
The result should be:
C = {1,2,3;'e','f','g'};
Help is greatly appreciated

 Respuesta aceptada

Matt Fig
Matt Fig el 27 de Sept. de 2012
A(all(~cellfun('isempty',B),2),:)

3 comentarios

Matt Fig
Matt Fig el 27 de Sept. de 2012
Editada: Matt Fig el 27 de Sept. de 2012
Leon comments:
"Great! Thank you very much. Can you tell me as well how I get the exact inverse, I mean all entries of A where B is empty?
Regards!"
Matt Fig
Matt Fig el 27 de Sept. de 2012
Yes, just take off the ~.
A(all(cellfun('isempty',B),2),:)
Léon
Léon el 27 de Sept. de 2012
Thank you very much indeed!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Preguntada:

el 27 de Sept. de 2012

Community Treasure Hunt

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

Start Hunting!

Translated by