Vectorize two for loops

Respuestas (2)

David Hill
David Hill el 19 de Nov. de 2020
Editada: David Hill el 19 de Nov. de 2020

0 votos

[i,j]=meshgrid(1:100,1:200);
TheOne=reshape(sum((Png1(:,i)-Png2(:,j)).^2),100,[]);

4 comentarios

Master Blabla
Master Blabla el 19 de Nov. de 2020
Could You get a little simple solution?
David Hill
David Hill el 19 de Nov. de 2020
Does not get any simpler.
Master Blabla
Master Blabla el 19 de Nov. de 2020
It does not work correctly
David Hill
David Hill el 19 de Nov. de 2020
Made a mistake. Try this.
[i,j]=meshgrid(1:100,1:200);
TheOne=reshape(sum((Png1(:,i)-Png2(:,j)).^2),200,[])';

Iniciar sesión para comentar.

CHENG QIAN LAI
CHENG QIAN LAI el 24 de Nov. de 2020

0 votos

[i,j]=ndgrid(1:100,1:200);
% 1 2 3 . . . 200
%---------------------------
% i= 1 1 1 . . . 1 | 1
% 2 2 2 . . . 2 | 2
% 3 3 3 . . . 3 | 3
% . . . | .
% . . . | .
% . . . | .
% 100 100 100 . . . 100 | 100
%---------------------------
% j= 1 2 3 . . . 200 | 1
% 1 2 3 . . . 200 | 2
% 1 2 3 . . . 200 | 3
% . . . | .
% . . . | .
% . . . | .
% 1 2 3 . . . 200 | 100
TheOne = i+j;

Categorías

Más información sobre Programming en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 19 de Nov. de 2020

Respondida:

el 24 de Nov. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by