Cell array: select only 1x3 double cells
조회 수: 5 (최근 30일)
이전 댓글 표시
Hi everyone,
i have a 1x4 cell array like this:
{[0.1]} {1×3 double} {[0.02]} {1×3 double}
and i want to extract only the 1x3 double cells (of which I do not know the exact location into cell array).
Thank's a lot!
Riccardo Rossi
댓글 수: 0
채택된 답변
Stephen23
2019년 1월 15일
편집: Stephen23
2019년 1월 15일
Where C is your cell array:
X = cellfun('length',C)==3;
out = C(X)
댓글 수: 7
Guillaume
2019년 1월 15일
So It should Be Faster Because There's No Overloading Involved?
It is faster because cellfun use a different algorithm when using the backward compatible syntax. The built-in code does not call any other function when iterating over the elements, it's got its own implementation of length.
One side effect of that is that if you've overloaded length for a type in the cell array, that overload won't get called. For that reason, I personally wouldn't recommend using the old syntax unless you're 100% certain that your cell array will never ever contain objects. There's a reason the old syntax has been deprecated.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!