Extracting vectors from big vector

1 visualización (últimos 30 días)
HYZ
HYZ el 17 de Mayo de 2020
Comentada: HYZ el 19 de Mayo de 2020
Hi,
I have a vector:
a = [1 3 4 2 3 4 5 6 3 4 5 6 8 9 10 9 8 7 6 7 8 9 8 7 5 4 3 2 4 5 3 1 2 4 4 3 2 4 6 5 4 6 7 9 9 10 9 8 7 6 7 8 9 8 7 5 4 3 2 4 5 3 1];
The output I would like to have is one cell: {[3 4 2 3 4 5 6 3 4 5 6 8]; [4 4 3 2 4 6 5 4 6 7]} as underlined in the original vector. The code I have written is shown below. I am stuck with getting a very long vector for the code I wrote.
Could anyone please advise how to correct the code? Thanks a lot!
The purpose is to split general forward and back directions. The values are like positions. for example, I am aware that there are backward tracks in the desired output [3 4 2 3 4 5 6 3 4 5 6 8]. I would like to ignore first. 1,2,9 and 10 are positions at the extremes which are excluded as min(a)+2 and max(a) -2.
a = [1 3 4 2 3 4 5 6 3 4 5 6 8 9 10 9 8 7 6 7 8 9 8 7 5 4 3 2 4 5 3 1 2 4 4 3 2 4 6 5 4 6 7 9 9 10 9 8 7 6 7 8 9 8 7 5 4 3 2 4 5 3 1 ];
start = min(a)+2;
ed = max(a) -2;
m = length(a);
f = 1;
i = 2; k=1;
while i < m
if a(i) >= start && a(i-1) <= start && a(i+1) >= a(i)
fwd1(k) = a(i);
for j = i+1:m-1
if a(j+1) >= ed && a(j+2) >= a(j+1) && a(j) <= a(j+1)
fwd2(k) = a(j);
output{k} = a (i:j);
end
end
i=j+1;
else
i = i+1;
end
k= k+1;
end

Respuestas (1)

Nikhil Sonavane
Nikhil Sonavane el 19 de Mayo de 2020
Can you explain your question in a more detailed way on what factors are you extracting data from the larger array? You may also refer to this link for some help.
  1 comentario
HYZ
HYZ el 19 de Mayo de 2020
I would like to extract two highlighted vectors and keep them in a cell array. The two vectors are for the forward going values. within two wanted vectors, some backward traces can seen and I want to ignore them. Only when backward traces are continuous for so many times (non-highlighted part), will they be excluded from extracting. Thanks. Please let me know if my question isn't clear.

Iniciar sesión para comentar.

Categorías

Más información sobre NaNs 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