find element in cell
2 次查看(过去 30 天)
显示 更早的评论
Dear all, I've problem with the cell,
a= {[67 8 33] [1 2 3 5] [2 88 5] [3 66 7 90] [3] [66 78 12 1 44 6 77 3]},
how to find each cell have number 3. answer expect it is:
b= {[1 2 3 5] [3 66 7 90] [3] [66 78 12 1 44 6 77 3]}
thanks all
0 个评论
回答(2 个)
KSSV
2017-7-12
a= {[67 8 33] [1 2 3 5] [2 88 5] [3 66 7 90] [3] [66 78 12 1 44 6 77 3]} ;
b= {[1 2 3 5] [3 66 7 90] [3] [66 78 12 1 44 6 77 3]} ;
iwant = cell([],1) ;
count = 0 ;
for i = 1:length(a)
if any(a{i}==3)
count = count+1 ;
iwant{count} = a{i} ;
end
end
iwant
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!