How to vectorize this function:
for i=1:100
for j=1:200
TheOne(i,j) = i+j;
end
end

답변 (2개)

David Hill
David Hill 2020년 11월 19일
편집: David Hill 2020년 11월 19일

0 개 추천

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

댓글 수: 4

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

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

CHENG QIAN LAI
CHENG QIAN LAI 2020년 11월 24일

0 개 추천

[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;

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

태그

질문:

2020년 11월 19일

답변:

2020년 11월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by