Arrays 在具有特定条件的结构中选择单元格
数据看起来更像这样:Arrays 在具有特定条件的结构中选择单元格,arrays,matlab,struct,Arrays,Matlab,Struct,数据看起来更像这样: T = struct('Direction', {[1,1,1,1],[1,1,2,1],[2,2,2,2,2], [2,2,2,2,1,2], [2,2,2,2,2],[3,1,4,5]}, 'Trial', {'correct','incorrect','incorrect','correct','correct','incorrect'}); 这只是一个示例,我还有其他字
T = struct('Direction',
{[1,1,1,1],[1,1,2,1],[2,2,2,2,2],
[2,2,2,2,1,2], [2,2,2,2,2],[3,1,4,5]},
'Trial',
{'correct','incorrect','incorrect','correct','correct','incorrect'});
这只是一个示例,我还有其他字段
T = T(arrayfun(@(x) all(x.Direction == 2), T));
我已经有了上面的代码,可以正常工作,但是它只给了我[2,2,2,2,2]
,它没有给我[2,2,2,2,1,2]
的单元格,因为它也有1
我尝试使用
您可以将条件更改为
sum( x.Direction == 2 ) + 1 >= numel( x.Direction )
即使其中一个元素是1
也应该返回true
,谢谢您的回答。代码没有错误,但我仍然没有得到带有[2,2,2,2,1,2]的单元格。