How to separate a vector into sub-vectors?
古いコメントを表示
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 件のコメント
James Tursa
2016 年 7 月 6 日
How large is your real problem?
Taner Cokyasar
2016 年 7 月 6 日
編集済み: Taner Cokyasar
2016 年 7 月 6 日
Taner Cokyasar
2016 年 7 月 6 日
James Tursa
2016 年 7 月 6 日
How are you doing the multiply? Inner product? If so, then you really really do not want to do what you are proposing. Instead you should be reshaping your original vector into a matrix and then doing a simple matrix multiply. Please post a small example using your 9x1 above to show the exact "multiply ... by a row vector" calculation you would like to do and the expected result. Then we can point you towards a better way of doing it.
Taner Cokyasar
2016 年 7 月 6 日
編集済み: Taner Cokyasar
2016 年 7 月 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.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Surrogate Optimization についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!