Borrar filtros
Borrar filtros

How to take first element from the cell?

2 visualizaciones (últimos 30 días)
laith Farhan
laith Farhan el 29 de Jul. de 2018
Comentada: Stephen23 el 30 de Jul. de 2018
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>>>>

Respuestas (1)

Stephen23
Stephen23 el 29 de Jul. de 2018
Editada: Stephen23 el 29 de Jul. de 2018
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 comentarios
laith Farhan
laith Farhan el 29 de Jul. de 2018
Thanks a lot Stephen , that really help
Stephen23
Stephen23 el 30 de Jul. de 2018
@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.

Iniciar sesión para comentar.

Categorías

Más información sobre Graphics Object Programming en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by