Keep strings seperated in array

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

madhan ravi
madhan ravi 2020년 11월 18일
Unclear
Nathalie Borst
Nathalie Borst 2020년 11월 19일
편집: Nathalie Borst 2020년 11월 19일
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'

답변 (1개)

Steven Lord
Steven Lord 2020년 11월 19일

0 개 추천

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

Nathalie Borst
Nathalie Borst 2020년 11월 19일
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?

이 질문은 마감되었습니다.

질문:

2020년 11월 18일

마감:

2021년 8월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by