How to normalize plot?
Show older comments
How to normalize the plot to one?
clc;clear all;close all;
syms x y
x0 = -.02:0.001:.02;lambda=532*10^-9;
y0 = -.02:0.001:.02;w0 = 0.002;
omegax=1;omegay=2;zr=pi*w0^2/lambda;
m = 2;
s=1;k=0.0002;Rx=zr;Ry=Rx;
[X0,Y0] = meshgrid(x0,y0);
f = @(x0,y0)sinh((omegax*x0+omegay*y0)/w0).*exp(-(x0.^2+y0.^2)/w0^2).*(x0+(1i*s.*y0)).^m.*exp((1i*k/2)*((x0^2/Rx)+(y0^2/Ry)));
I_numerical = real(abs(vpa(f)));
figure
fcontour(real(I_numerical), [-1 1 -1 1]*1E-2, 'Fill','on', 'MeshDensity',150)
colormap('hot');
colorbar('vert');
axis('equal')
Answers (1)
x0 = -.02:0.001:.02;lambda=532*10^-9;
y0 = -.02:0.001:.02;w0 = 0.002;
omegax=1;omegay=2;zr=pi*w0^2/lambda;
m = 2;
s=1;k=0.0002;Rx=zr;Ry=Rx;
[X0,Y0] = meshgrid(x0,y0);
f = @(x0,y0)sinh((omegax*x0+omegay*y0)/w0).*exp(-(x0.^2+y0.^2)/w0^2).*(x0+(1i*s.*y0)).^m.*exp((1i*k/2)*((x0^2/Rx)+(y0^2/Ry)));
Z0 = arrayfun(@(x,y)f(x,y),X0,Y0);
contourf(X0,Y0,real(abs(Z0))/max(real(abs(Z0(:)))))
colormap('hot');
colorbar('vert');
axis('equal')
6 Comments
Athira T Das
on 4 May 2023
Star Strider
on 4 May 2023
Try this —
contourf(X0,Y0,real(abs(Z0))/max(real(abs(Z0(:)))), 'EdgeColor','none')
.
I_numerical is an array of numerical values of size 1x500, not a function.
So setting
f = @(x,y) I_numerical;
makes no sense since f(x,y) will return this 1x500 array for each value pair (x,y).
I don't know against which independent variable(s) you intend I_numerical to plot.
Athira T Das
on 4 May 2023
Torsten
on 4 May 2023
Then arrange your code such that I_numerical has size 500x500 since x has 500 elements and y has 500 elements.
At the moment, I_numerical has size 1x500.
Categories
Find more on Contour Plots 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!
