Borrar filtros
Borrar filtros

Why is my for loop code not incrementing correctly?

8 visualizaciones (últimos 30 días)
Raushan
Raushan el 15 de Sept. de 2022
Comentada: Walter Roberson el 15 de Sept. de 2022
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.

Respuestas (1)

Walter Roberson
Walter Roberson el 15 de Sept. de 2022
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.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by