필터 지우기
필터 지우기

How to take first element from the cell?

조회 수: 2 (최근 30일)
laith Farhan
laith Farhan 2018년 7월 29일
댓글: Stephen23 2018년 7월 30일
Dear all,
I have a cell
d={[3,80,32,13] [3,80,17] [3,45,18] [3,45,20] [3,80,32] [3,45] [3,80,47] [3,45,93,62] [3,80] [3,45,93]}
Also I have vector c= [80 45];
The question is : How to take the first element that locate it after vector c numbers ?
The expected result is =
{[32] [17] [18] [20] [32] [] [47] [93] [] [93]}
Also I would like to get other elements that locate it after the first element in another cell, for example:
x = {[13] [] [] [] [] [] [62] [] []}
please help>>>>

답변 (1개)

Stephen23
Stephen23 2018년 7월 29일
편집: Stephen23 2018년 7월 29일
Something like this (untested, but should get you started):
N = numel(d);
R = cell(1,N);
X = cell(1,N);
for k = 1:N
idx = ismember(d{k},[80,45]);
idx = [false,idx(1:end-1)];
if any(idx)
R{k} = d{k}(find(idx,1,'first'));
end
idx = [false,idx(1:end-1)];
if any(idx)
X{k} = d{k}(find(idx,1,'first'));
end
end
  댓글 수: 2
laith Farhan
laith Farhan 2018년 7월 29일
Thanks a lot Stephen , that really help
Stephen23
Stephen23 2018년 7월 30일
@laith Farhan: I hope that it helped. Remember to accept the answer that helped you most: accepting answers is the easiest way to show your appreciation to the volunteers who help you on this forum.

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

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by