Effacer les filtres
Effacer les filtres

How to take first element from the cell?

2 vues (au cours des 30 derniers jours)
laith Farhan
laith Farhan le 29 Juil 2018
Commenté : Stephen23 le 30 Juil 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>>>>

Réponses (1)

Stephen23
Stephen23 le 29 Juil 2018
Modifié(e) : Stephen23 le 29 Juil 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 commentaires
laith Farhan
laith Farhan le 29 Juil 2018
Thanks a lot Stephen , that really help
Stephen23
Stephen23 le 30 Juil 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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Graphics Object Programming dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by