質問

I have a large dataset, x, consisting of 16201 x 49 cells, the first row contains labels e.g.:

'Entry1label' 'Entry2label', 'Entry3label', 'Entry4label'
'stimuli 1'   'stimuli 2'    0.1            10
'stimuli 1'   'stimuli 3'    0.1            10
'stimuli 2'   'stimuli 1'    0.1            40

Column 4 consist of cells with values of either 10, 20, 40 or 60. All of the columns have repeated entries (but different combinations across the columns). I want to filter the cell array for all entries in, e.g. 'Entry4label', that equal e.g. 10. I've tried:

x([x{2:end, 4}] == 10, :)

This almost works, however, about every twenty cells there's a cell with value 40 left in! Similarly, if I try with 20, I get spurious occurrences of 10. If I use 40, I get spurious occurrences of 20, and finally for 60 I get some (but very few), 40s.

Any idea as to what is going on?

役に立ちましたか?

解決

Code

out = x(find(cell2mat(x(2:end,4))==10)+1,:)

Output

out = 

    'stimuli 1'    'stimuli 2'    [0.1]    [10]
    'stimuli 1'    'stimuli 3'    [0.1]    [10]

The problem was that the first element is a string for the fourth column.

他のヒント

Here: x([x{2:end, 4}] == 10, :)

Because you're finding the locations within a subset of the column, it's actually taking the row offset by one. I guess that your values in that column are mostly in blocks with an occasional change, so it makes it look as if it's matching most of them.

You can put the offset back:

x(find([x{2:end, 4}]==40)+1,:)

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top