Repeat the concatenation of every n rows
3 views (last 30 days)
Show older comments
I have a large data set in which there are 178 recordings for every 1 second displayed in 1 row. I want to concatenate 23 rows at a time, to create rows that have 23 second time intervals. In total i need to create 500 of these 23 second rows. I have the following code for the horizontal concatenation of 23 rows:
for i = 1
section1 = horzcat(data(i,1:178),data(i+1,1:178),data(i+2,1:178),data(i+3,1:178),data(i+4,1:178),data(i+5,1:178),data(i+6,1:178),data(i+7,1:178),data(i+8,1:178),data(i+9,1:178),data(i+10,1:178),data(i+11,1:178),data(i+12,1:178),data(i+13,1:178),data(i+14,1:178),data(i+15,1:178),data(i+16,1:178),data(i+17,1:178),data(i+18,1:178),data(i+19,1:178),data(i+20,1:178),data(i+21,1:178),data(i+22,1:178));
end
I want to do something like this for the remaining sections:
s = ((i-1)/23)+1
while s <= 500
for i = i + 23
section(s) = horzcat(data(i,1:178),data(i+1,1:178),data(i+2,1:178),data(i+3,1:178),data(i+4,1:178),data(i+5,1:178),data(i+6,1:178),data(i+7,1:178),data(i+8,1:178),data(i+9,1:178),data(i+10,1:178),data(i+11,1:178),data(i+12,1:178),data(i+13,1:178),data(i+14,1:178),data(i+15,1:178),data(i+16,1:178),data(i+17,1:178),data(i+18,1:178),data(i+19,1:178),data(i+20,1:178),data(i+21,1:178),data(i+22,1:178));
end
end
I'm not that familiar with indexing and am getting errors for this. If anyone could help it would be greatly appreciated!
0 Comments
Accepted Answer
Jon
on 12 Apr 2019
I think this should do what you want:
s = reshape(data',178*23,500)'
Note the use of the transpose (accent symbol) first to transpose data, and then to transpose the result of the reshaping.
The reshaping does this kind of thing nicely, but MATLAB indexes data columnwise, and you are looking at the data rowwise. So you first need transpose to get the rows into columns (so things will be columnwise) and then at the end you transpose back.
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!