take first element from each cell
1 次查看(过去 30 天)
显示 更早的评论
Dear all, I wanna your help with this problem:
Is there any way to take the first element from each cell depend on b vector:
a=[{[1,9,79,3] [2,29,16,7,3] 3 [4,74,3] [5,73,79,3] [6,56,3] [7,3]}] ;
b = [79,3,74,10];
the result should be:
result_79: [ 1 5];
result_3: [ 1 2 3 4 5 6 7];
result_74: [ 4];
result_10: [ ];
thanks...
采纳的回答
the cyclist
2017-1-2
Here's one way:
a ={[1,9,79,3] [2,29,16,7,3] 3 [4,74,3] [5,73,79,3] [6,56,3] [7,3]} ;
b = [79,3,74,10];
nb = numel(b);
c = cell(1,nb);
for ia = 1:nb
c{ia} = find(cellfun(@(x)any(ismember(x,b(ia))),a));
end
更多回答(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!