Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Keep strings seperated in array

1 visualización (últimos 30 días)
Nathalie Borst
Nathalie Borst el 18 de Nov. de 2020
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
So I have a structure with three types of conditions 'dcol', 'dsym' & 'c'
I want to filter through the structure per condition using indexing however this doesn't work:
c = [participant.condition]
gives: 'dcolcdsymdcoldcoldsymdcolcdsymdsymdcoldcolcdcol' > I want them to be seperated per condition
RT = [participant.RT]
i = c == 'c' > logical array out of bound cause it takes every character rather than every string
  2 comentarios
madhan ravi
madhan ravi el 18 de Nov. de 2020
Unclear
Nathalie Borst
Nathalie Borst el 19 de Nov. de 2020
Editada: Nathalie Borst el 19 de Nov. de 2020
So now it merges all the seperate strings 'c', 'dcol', 'dsym, 'c', 'dsym, 'c', 'dcol' etc to one long string 'cdcoldsymcdsym' when I do c = [participant.condition]
When I want to look through those conditions for condition 'c' it now looks at every character which in this example would give a logical array of [1 0 1 0 0 0 0 0 0 1 0 0 0 0], whereas I want this as output: [1 0 0 1 0 1] when I do i = c == 'c'

Respuestas (1)

Steven Lord
Steven Lord el 19 de Nov. de 2020
s = struct('abc', {'def', 'ghi', 'jkl'})
s = 1x3 struct array with fields:
abc
charVec = [s.abc]
charVec = 'defghijkl'
cellVec = {s.abc}
cellVec = 1x3 cell array
{'def'} {'ghi'} {'jkl'}
  1 comentario
Nathalie Borst
Nathalie Borst el 19 de Nov. de 2020
Thanks for your reply! However, when I create a cell array I can't filter. When I try: cellVec == 'def'. How can I get a logical array of all the rows containing 'def' showing a one and everything else a 0?

Community Treasure Hunt

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

Start Hunting!

Translated by