take first element from each cell

조회 수: 2 (최근 30일)
skysky2000
skysky2000 2017년 1월 2일
댓글: skysky2000 2017년 1월 2일
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...
  댓글 수: 1
José-Luis
José-Luis 2017년 1월 2일
What have you tried so far?

댓글을 달려면 로그인하십시오.

채택된 답변

the cyclist
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
  댓글 수: 1
skysky2000
skysky2000 2017년 1월 2일
Thanks alot Cyclist,,, that amazing

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by