Return the position of a vector in a cell array that is length 3

1 次查看(过去 30 天)
Hello everyone,
Was wondering if you could help, I'm a bit of a newbie so this may be a very simple question.
I have a cell array called nodes which contains [1,2,3], [3,4,2,1] and [1,2]
I want to return the position of the vector in the cell array that is length 3 please
Thank you

采纳的回答

Stephen23
Stephen23 2020-4-20
>> C = {[1,2,3],[3,4,2,1],[1,2]};
>> X = cellfun(@numel,C)==3 % logical index
X =
1 0 0
>> find(X) % linear index
ans = 1

更多回答(1 个)

David Hill
David Hill 2020-4-19
I believe the only way is to loop through the cell array
for k=1:length(c)
if length(c{k})==3
C=c{k};
break;
end
end

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by