Why is my for loop code not incrementing correctly?
4 次查看(过去 30 天)
显示 更早的评论
Hi!
In the code below, the data1 matrix has 100000 data in each of the two columns. I want to read the second column and divide whole column 2 with a gap of 256. That means, I want data from 1 to 256 in one matrix and then 257 to 512 in another and so on. But, the for loop that I have used is giving me only one output of the data , ie one matrix. I want to have all these data separted with a record size of 256 in differnet tables or matrices. What am i missing here?
start= 1;
last= 256;
for n= 1:1:389
% fprintf("%d \n", n)
n = data1(start:last, 2);
start= last+1;
last= start+ 255;
end
Any help would be very much appreciated.
0 个评论
回答(1 个)
Walter Roberson
2022-9-15
N = 256;
last = floor(size(data1,2)/N) * 256;
buffered = reshape(data1(1:last, 2), N, []);
The entries will now be down columns.
| want to have all these data separted with a record size of 256 in differnet tables or matrices.
That would require creating variables dynamically, which we highly recommend not be done.
1 个评论
Walter Roberson
2022-9-15
Please read http://www.mathworks.com/matlabcentral/answers/304528-tutorial-why-variables-should-not-be-named-dynamically-eval for information about why we strongly recommend against creating variable names dynamically.
另请参阅
类别
在 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!