MATLAB: How to vectorize the following code snippet MATLABvectorization x = -1.0:0.2:1.0; y = -2:0.25:3; length_x = length(x); length_y = length(y); for nx=1:length_x for ny=1:length_y result(nx, ny) = exp(x(nx)^2-y(ny)^2); end end Best Answer x = -1.0:0.2:1.0;y = -2:0.25:3;[X,Y] = meshgrid(x,y) ; result = exp(X.^2-Y.^2); Related SolutionsMATLAB: Dimensions of arrays being concatenated are not consistent. discpath = [r(i+1,1)-r(i,1);r(i+1,2)-r(i,2);u(r(i+1,1),r(i+1,2)); u(r(i,1),r(i,2))]; % semicolon missing ^ MATLAB: How to simplify the given code snippet colX2 = reshape(bsxfun(@plus,X,bsxfun(@times,t',dx(1:3))),[],1);orcolX2 = reshape(bsxfun(@plus,X,t'*dx(1:3)),[],1) Related QuestionWhat is the problem with this code snippetHow to solve a first order partial differential equationContour plot for given x,y,z
Best Answer