For example
x = [1 2 3 4 5 6; 7 8 9 10 11 12;13 14 15 16 17 18;1 2 3 4 5 6]
I want sum of [1 2 3 7 8 9] which is = 72 and [4 5 6 10 11 12 15 16 17 18] which is 114 , then [1 2 3 1 1 1 2 4 3] which is 18 and so on

2 comentarios

Azzi Abdelmalek
Azzi Abdelmalek el 1 de Mzo. de 2014
Editada: Azzi Abdelmalek el 1 de Mzo. de 2014
This is not clear. What and so on means here?
renuka
renuka el 2 de Mzo. de 2014
for 600x600 matrices the pattern should be sum of 3x3 and produce a matrix of the sum example [72 114 18]

Iniciar sesión para comentar.

 Respuesta aceptada

Image Analyst
Image Analyst el 2 de Mzo. de 2014

0 votos

I just answered this, in http://www.mathworks.com/matlabcentral/answers/119568#comment_199374, your duplicate question. Anyway, again, you can use conv2():
result = conv2(x, ones(3), 'valid');
It gives you just what you want - the sums in a sliding window.

2 comentarios

renuka
renuka el 2 de Mzo. de 2014
this answer is for the previous one. But in this question its
x = [1 2 3 4 5 6; 7 8 9 10 11 12;13 14 15 16 17 18;1 2 3 4 5 6] sum of [1 2 3 7 8 9] = 30 and [4 5 6 10 11 12] = 48 and [13 14 15 1 2 3] = 48 and [ 16 17 18 4 5 6] = 66
the result = [30 48; 48 66]
Image Analyst
Image Analyst el 2 de Mzo. de 2014
x = [1 2 3 4 5 6; 7 8 9 10 11 12;13 14 15 16 17 18;1 2 3 4 5 6]
theSums = conv2(x, ones(2,3), 'same') % Compute sums
theResult = theSums(1:2:end, 2:3:end) % Subsample

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 1 de Mzo. de 2014

Comentada:

el 2 de Mzo. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by