Extracting vectors from big vector

조회 수: 1 (최근 30일)
HYZ
HYZ 2020년 5월 17일
댓글: HYZ 2020년 5월 19일
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

답변 (1개)

Nikhil Sonavane
Nikhil Sonavane 2020년 5월 19일
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
HYZ
HYZ 2020년 5월 19일
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.

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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by