how to 7004829X1 into 5000X1 blocks?
1 次查看(过去 30 天)
显示 更早的评论
I want to separate 1400 blocks and they receive 10 data from the previous and next matrices
2 个评论
采纳的回答
Image Analyst
2018-12-19
You say "they receive 10 data from the previous and next matrices" so you want an overlap of 10 when the window jumps to the next location.
You can use blockproc() if you have the Image Processing Toolbox to process those blocks with jumps of whatever you want and a window size of whatever you want. For example a window size of 1400 but the window jumps 1390 each time, instead of 1400, so that you have an overlap of 10 in each window. See attached example and adapt as needed.
5 个评论
Image Analyst
2018-12-19
Why do you need to save them? Is there some reason you need them after the loop exits? Why can't you just process them right there in the loop?
If for some reason you need the blocks later, after the loop is done, then you can save them to a cell array. You could save them to a 2-D numerical array but since the last block is only 3859 elements long, you can't do that (unless you wanted to pad the rest with some number).
thisBlock{k} = data(index1:index2);
更多回答(2 个)
Mark Sherstan
2018-12-19
编辑:Mark Sherstan
2018-12-19
Try this (you will have to adjust for your larger vector) but should do the trick:
A = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15];
count = 1;
for ii = 3:3:length(A)-3
idxLow = ii-2;
idxHigh = ii+2;
out{count} = A(idxLow:idxHigh)';
count = count + 1;
end
4 个评论
Mark Sherstan
2018-12-19
Sorry I missed a counter. Correction was made in the original post and located below for your convenience.
A = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15];
count = 1;
for ii = 3:3:length(A)-3
idxLow = ii-2;
idxHigh = ii+2;
out{count} = A(idxLow:idxHigh)';
count = count + 1;
end
out =
1×4 cell array
{5×1 double} {5×1 double} {5×1 double} {5×1 double}
TADA
2018-12-19
编辑:TADA
2018-12-19
You can either generate a matrix with each column representing one 1400 part vector as you specified, or generate a cell array, with each cell containing that vector.
a = (1:15)';
% generate a matrix of 5x3
b = reshape(a, [5,3])
b =
1 6 11
2 7 12
3 8 13
4 9 14
5 10 15
% generate a cell array of 3 cells with 5x1 vector in each cell
c = mat2cell(a, repmat(5, 1, 3), 1);
celldisp(c);
c{1} =
1
2
3
4
5
c{2} =
6
7
8
9
10
c{3} =
11
12
13
14
15
as for the large vector you have:
a = (1:7000000)';
b = reshape(a, [1400, 5000]);
c = mat2cell(a, repmat(1400, 1, 5000), 1);
5 个评论
Image Analyst
2018-12-19
That's an example of overlap of 1. You can use blockproc() if you have the Image Processing Toolbox to process those blocks with jumps of whatever you want and a window size of whatever you want. For example a window size of 1400 but the window jumps 1390 each time, instead of 1400 so that you have an overlap of 10 in each window. See attached example in my Answer.
TADA
2018-12-19
编辑:TADA
2018-12-19
Thanks Image Analyst for pointing out my mistake.
Here's the rectified version:
% input
a = (1:13);
% settings
overlap = 2;
n = 5;
% generate the indices of column starts
i = 1:(n-overlap):(length(a)-n);
% generate the output matrix
x = bsxfun(@plus, i, (0:(n-1))');
x =
1 4 7
2 5 8
3 6 9
4 7 10
5 8 11
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multidimensional Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!