How can I extract data and match it from two different data??
1 次查看(过去 30 天)
显示 更早的评论
Hello.
for example, I have two data.
1 is [ 0 0 0 0 1 1 1 0 0 0 ] and
2 is [ 5 5 5 5 10 10 10 6 6 6 ]
What I want to do is that first find a value '1' position in data 1* 5th,6th,7th) and extract a data from same position in data 2.(10 10 10 )
in original dat there are more then 5000 sequence... :(
Is there any way to do this?
0 个评论
采纳的回答
the cyclist
2020-2-12
编辑:the cyclist
2020-2-12
If your first vector is only ones and zeros, then it is as simple as
idx = [ 0 0 0 0 1 1 1 0 0 0 ];
b = [ 5 5 5 5 10 10 10 6 6 6];
b(idx)
If the first vector has more general values, and you want the values of the second vector where the non-zeros are then
a = [ 0 0 0 0 2 1 6 0 0 0 ];
b = [ 5 5 5 5 10 10 10 6 6 6];
b(a~=0)
If you actually need the positions of the non-zero elements, then
pos = find(a);
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!