apply function with two variables
Mostrar comentarios más antiguos
I would like to apply the 2D Gaussian function for several values of x and y, for example x = 1:1280 and y = 1:1024. The other input arguments are scalar.
function [ intensity_value ] = twoDimensionalGaussian( x, y, x_centre, y_centre, sigma_x, sigma_y, sigma_xy, amplitude, background)
x_normalised = (x - x_centre)/sigma_x;
y_normalised = (y - y_centre)/sigma_y;
intensity_value = background + amplitude*exp(-(x_normalised^2 + y_normalised^2 + 2*sigma_xy/(sigma_x*sigma_y)*x_normalised*y_normalised));
end
I could write the following for loop:
nb_pixel_horiz = 1280;
nb_pixel_verti = 1024;
I = zeros(nb_pixel_horiz,nb_pixel_verti);
for x = 1:nb_pixel_horiz
for y = 1:nb_pixel_verti
intensity_value = twoDimensionalGaussian( x, y, x_centre, y_centre, sigma_x, sigma_y, sigma_xy, amplitude, background);
I(x,y) = intensity_value;
end
end
Would this solution be the most appropriate or is there another one that is faster or easier?
Thank you!
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Log Plots en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!