How to vectorize the following code snippet?
1 view (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
KSSV
on 15 Feb 2021
x = -1.0:0.2:1.0;
y = -2:0.25:3;
[X,Y] = meshgrid(x,y) ;
result = exp(X.^2-Y.^2);
0 Comments
More Answers (0)
See Also
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!