How to do this programming
2 次查看(过去 30 天)
显示 更早的评论
Hello,
I have X=[1,2,3,4,5,..........,20]
Now I want to divide X into 5 blocks where each block should contain 4 elements..
I need B1=[1,2,3,4]
then B2=[5,6,7,8]and so on
采纳的回答
Jonathan Sullivan
2013-5-28
You don't actually want 5 different variables. You want to reshape the variable and index into it.
Example:
X = 1:20;
B = reshape(X,4,[]);
B(:,1)
B(:,2)
0 个评论
更多回答(1 个)
Image Analyst
2013-5-28
I know it seems really obvious, but have you tried:
B1 = X(1:4);
B2 = X(5:8);
B3 = X(9:12);
B4 = X(13:16);
B5 = X(17:20);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!