Extract value in cell array based on

9 visualizaciones (últimos 30 días)
Robert Eisenbecker
Robert Eisenbecker el 12 de Jun. de 2017
Editada: Robert Eisenbecker el 13 de Jun. de 2017
Hello, I have a 1x3 cell array:
str = strings(6,1)
str(1) = 'A'
str(2) = 'B'
str(3) = 'A'
str(4) = 'B'
str(5) = 'A'
str(6) = 'B'
str2 = strings(6,1)
str(1) = 'r'
str(2) = 'r'
str(3) = 't'
str(4) = 's'
str(5) = 't'
str(6) = 'm'
a = [345; 344; 234; 234; 235; 231]
CA{1} = str
CA{2} = str2
CA{3} = a
My task is to extract certain values of the third cell vector based on some conditions pertaining to the first two cell vectors, e.g.: If cellvector1 = 'A' AND cellvector2 = 't' --> what is the corresponding value in cellvector 3? (so in this case 234 and 235)
Thank you very much in advance!

Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 12 de Jun. de 2017
s = [str,str2];
strvector = string({'A','t'});
out = a(ismember([str,str2],string({'A','t'}),'rows'))
  1 comentario
Robert Eisenbecker
Robert Eisenbecker el 13 de Jun. de 2017
Editada: Robert Eisenbecker el 13 de Jun. de 2017
EDIT: It works now, my mistake, thank you very much!!!
Thank you for your reply! But if I run the code it returns:
out =
0×1 empty double column vector
But I need it to return the numbers 234 and 235..

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre String Parsing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by