Why is my for loop code not incrementing correctly?

6 Ansichten (letzte 30 Tage)
Raushan
Raushan am 15 Sep. 2022
Kommentiert: Walter Roberson am 15 Sep. 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.

Antworten (1)

Walter Roberson
Walter Roberson am 15 Sep. 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.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by