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