# Array manipulation: Suppose you have an array.How to take windows with overlapping along column and repeat to next doing same

3 visualizzazioni (ultimi 30 giorni)
MSP il 12 Gen 2017
Commentato: Kirby Fears il 23 Gen 2017
for example a= [1 2 3 4 5; 4 7 9 1 5; 8 7 3 2 1; 3 2 9 1 7]
so what is required to be done is take out a window of size 3 and shift the window 1 data point in the next iteration. SO the result will show
1 4 8
then 483 for the first column in 1st column of a new array.So the first array would have 6 elements and it will be a 6*5 array.
so the new array would have first two columns like 1st column [1;4;8;4;8;3] 2nd column [2;7;7;7;7;2]
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Kirby Fears il 12 Gen 2017
Modificato: Kirby Fears il 12 Gen 2017
Indexing and stacking as shown below will work for your example. Does this work for your real use case also?
a = [1 2 3 4 5; 4 7 9 1 5; 8 7 3 2 1; 3 2 9 1 7];
b = [a(1:end-1,:); a(2:end,:)];
##### 2 CommentiMostra NessunoNascondi Nessuno
MSP il 12 Gen 2017
Modificato: MSP il 12 Gen 2017
Thanks for the help, works for the example but would have rather wanted a general solution like when the window size gets bigger as well as the shift ;consider window 128,shift 64.The main objective is to get windows in same position of two different arrays like 'a' and then compare to find out the relationships.maybe looping can work too.if u got any better ideas pls share.
Kirby Fears il 23 Gen 2017
The example I posted is easily extended to general window and shift sizes. For example, my original solution can be written with window size 3 and step size 1.
windowSize = 3;
stepSize = 1;
a = [1 2 3 4 5; 4 7 9 1 5; 8 7 3 2 1; 3 2 9 1 7];
b = [a(1:windowSize,:); a(1+stepSize:windowSize+stepSize,:)];

Accedi per commentare.

### Categorie

Scopri di più su Linear Algebra in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by