How can I find the coordinates of a known vector, within a larger vector?
显示 更早的评论
I'd like to take a group of linear vectors, and find where a smaller known vector is placed within them.
For example if I have:
Vector1 = 3 2 4 1 3 2 4 1 3 2 4 2 4 3 4 3 1 4 2 2 3 4 1 4 2
Vector2 = 1 4 2 3 1 4 2 4 2 3 4 3 1 4 2 2 4 1 3 2 4 1 2 3 1 1 1
Vector3 = 1 4 2 3 4 1 4 2 3 1 4 3 4 3 1 4 2 1 4 2 3 1 4 1 3
Vector4 = 1 3 2 4 2 4 1 4 3 2 3 4 3 1 4 2 1 1 3 2 4 2 4 1 2 3
Vector5 = 1 3 2 4 2 1 1 1 3 4 3 2 3 4 3 1 4 2 1 1 3 2 4 2 4 1 2 3
ConstantVector = 3 4 3 1 4 2
I know that each of the vectors 1-5 have the ConstantVector in them somewhere. I would like to be able to quickly output the position of the vector in each case.
The end aim is to be able to put Vectors 1-5 into a matrix of zeros such the sections denoted by ConstantVector are all aligned in columns. For example the above vectors would become:
3 2 4 1 3 2 4 1 3 2 4 2 4|3 4 3 1 4 2|2 3 4 1 4 2 0 0 0 0 0 0
0 0 0 0 1 4 2 3 1 4 2 4 2|3 4 3 1 4 2|2 4 1 3 2 4 1 2 3 1 1 1
ConstantOverLaying = 0 0 1 4 2 3 4 1 4 2 3 1 4|3 4 3 1 4 2|1 4 2 3 1 4 1 3 0 0 0 0
0 0 0 1 3 2 4 2 4 1 4 3 2|3 4 3 1 4 2|1 1 3 2 4 2 4 1 2 3 0 0
0 1 3 2 4 2 1 1 1 3 4 3 2|3 4 3 1 4 2|1 1 3 2 4 2 4 1 2 3 0 0
I've put lines on either side of the ConstantVector just to show that they overlap.
My current thinking is that once I have the coordinates I can use them to automatically shift them left or right as needed when adding them to the matrix of zeroes. If anyone can think of any better ways to do this it is of course welcome.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!