Extracting vectors from big vector
1 回表示 (過去 30 日間)
古いコメントを表示
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
0 件のコメント
回答 (1 件)
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.
参考
カテゴリ
Help Center および File Exchange で NaNs についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!