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 Center および File ExchangeImage Processing Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by