Azzera filtri
Azzera filtri

How to take first element from the cell?

2 visualizzazioni (ultimi 30 giorni)
laith Farhan
laith Farhan il 29 Lug 2018
Commentato: Stephen23 il 30 Lug 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>>>>

Risposte (1)

Stephen23
Stephen23 il 29 Lug 2018
Modificato: Stephen23 il 29 Lug 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 Commenti
laith Farhan
laith Farhan il 29 Lug 2018
Thanks a lot Stephen , that really help
Stephen23
Stephen23 il 30 Lug 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.

Accedi per commentare.

Categorie

Scopri di più su Graphics Object Programming in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by