How to vectorize the following code snippet?

1 vue (au cours des 30 derniers jours)
Utku G
Utku G le 15 Fév 2021
Réponse apportée : KSSV le 15 Fév 2021
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

Réponse acceptée

KSSV
KSSV le 15 Fév 2021
x = -1.0:0.2:1.0;
y = -2:0.25:3;
[X,Y] = meshgrid(x,y) ;
result = exp(X.^2-Y.^2);

Plus de réponses (0)

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by