how to 7004829X1 into 5000X1 blocks?

조회 수: 1 (최근 30일)
Cem SARIKAYA
Cem SARIKAYA 2018년 12월 19일
댓글: Cem SARIKAYA 2018년 12월 20일
I want to separate 1400 blocks and they receive 10 data from the previous and next matrices
  댓글 수: 2
TADA
TADA 2018년 12월 19일
Could You Publish An Example Of The Input And Desired Output?
Cem SARIKAYA
Cem SARIKAYA 2018년 12월 19일
편집: Cem SARIKAYA 2018년 12월 19일
For example, if I have matrix: A = [1,2,3,4,5,6,7,8,9,10,11,12,13];
and I want matrices:
B = [1,2,3,4,5]; C = [4,5,6,7,8]; D=[8,9,10,11,12];
but i have 7000000x1 matrix and i need 1400 pieces matrix

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
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
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);
Cem SARIKAYA
Cem SARIKAYA 2018년 12월 20일
thank you very much you correct my perspective. I appreciate.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Mark Sherstan
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
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}
Cem SARIKAYA
Cem SARIKAYA 2018년 12월 19일
thank you very much but, how can I change it to 5000 values

댓글을 달려면 로그인하십시오.


TADA
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
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
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 CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by