How to separate a vector into sub-vectors?
4 次查看(过去 30 天)
显示 更早的评论
Assume, I have the following vector Zs (9x1):
0
0
1
0
1
0
0
1
0
I want to create sub-vectors such that each of them will include three numbers in the Zs, consecutively.
For example,
Zs1 = [0; 0; 1]
Zs2 = [0; 1; 0]
Zs3 = [0; 1; 0]
Thanks,
6 个评论
Stephen23
2016-7-7
@Taner Cokyasar: Don't create lots of variables like that! You will only make your code much slower, more complicated, and buggy. Oh, it it will also be much harder to debug! Read thsi carefully to know why:
The best solution: Keep your data in one variable, and learn to use indices effectively.
采纳的回答
James Tursa
2016-7-6
编辑:James Tursa
2016-7-7
Don't do that. Use cell arrays or some other method instead. E.g., see this link:
EDIT 7/6/2016:
OK, based on what you have recently posted, try this:
k = your row vector
Zs = your large column vector
n = numel(k);
scalars = k * reshape(Zs,n,[]);
The elements of scalars will be the values you want.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!