Matlab 如果行数大于阈值,如何查找单元格数组中的所有单元格数组?
我有一个单元格数组Matlab 如果行数大于阈值,如何查找单元格数组中的所有单元格数组?,matlab,indexing,cell-array,Matlab,Indexing,Cell Array,我有一个单元格数组B。B的每个元素都有不同的行号。如何仅访问行数大于阈值的B元素 我试过: A = B{cellfun('length', B) >= threshold}; 这可以在没有循环的情况下完成吗? B(cellfun('length', B) >= threshold ) 或 应该有用 它们都对内部单元数组中的元素进行计数 如果您真的只想要单元格,其中行数大于或等于阈值: B(cellfun('size', B, 1) >= threshold ) 或 示例
B
。B
的每个元素都有不同的行号。如何仅访问行数大于阈值的B
元素
我试过:
A = B{cellfun('length', B) >= threshold};
这可以在没有循环的情况下完成吗?
B(cellfun('length', B) >= threshold )
或
应该有用
它们都对内部单元数组中的元素进行计数
如果您真的只想要单元格,其中行数大于或等于阈值:
B(cellfun('size', B, 1) >= threshold )
或
示例
arr_Row1Col1 = {1};
arr_Row1Col2 = {1,2};
arr_Row2Col1 = {1;2};
arr_Row2Col2 = {1,2;3,4};
threshold = 2;
B = {arr_Row1Col1, arr_Row1Col2, arr_Row2Col1, arr_Row2Col2};
% All inner-cells that have more than one element
B(cellfun('length', B) >= threshold )
% All inner-cells that have more than one row
B(cellfun('size', B, 1) >= threshold )
产出:
B(cellfun(@(x) size(x, 1) >= threshold, B))
arr_Row1Col1 = {1};
arr_Row1Col2 = {1,2};
arr_Row2Col1 = {1;2};
arr_Row2Col2 = {1,2;3,4};
threshold = 2;
B = {arr_Row1Col1, arr_Row1Col2, arr_Row2Col1, arr_Row2Col2};
% All inner-cells that have more than one element
B(cellfun('length', B) >= threshold )
% All inner-cells that have more than one row
B(cellfun('size', B, 1) >= threshold )
ans = {1x2 cell} {2x1 cell} {2x2 cell}
ans = {2x1 cell} {2x2 cell}