imread(A,'1.jpg');这时,A是RGB的三维矩阵A=double(A);f=A[(:,:,1)+A(:,:,2)+A(:,:,3)]/3;得到灰度用循环grad(x,y)=sqrt((f(x,y)-f(x+1,y+1))^2+(f(x+1,y)-f(x,y+1))^2);