How to vectorize the following code snippet?

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

 Risposta accettata

x = -1.0:0.2:1.0;
y = -2:0.25:3;
[X,Y] = meshgrid(x,y) ;
result = exp(X.^2-Y.^2);

Più risposte (0)

Categorie

Scopri di più su MATLAB in Centro assistenza e File Exchange

Prodotti

Release

R2020b

Richiesto:

il 15 Feb 2021

Risposto:

il 15 Feb 2021

Community Treasure Hunt

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

Start Hunting!

Translated by