Clear Filters
Clear Filters

Automated plot using values from an initial graph

1 view (last 30 days)
I am trying to plot a graph using the the central minima values that are generated from an intial plot.
The attached images and code demonstrate what I am trying to achieve.
clear all;
%PARAMETERS
n1 = 3.43; n2 = 2.97; n0 = 1; n3 = 3.6;
c = 767e-9; l = 0e-9; u = 3000e-9;
figure;
CHARTS = tiledlayout('flow');
nexttile; grid on; grid minor; hold on
xlabel('Wavelength'); ylabel('Angle'); zlabel('Intensity')
zlim ([0 100]);
xlim ([700 800]);
for iRange = 80:-10:0
np = 20000; s = (u-l)/np;
Wavelength = zeros(1,np);
Intensity = zeros(1,np);
index = 1;
%WAVELENGTH RANGE
for range = l:s:u
incd = iRange*(pi/180);
a1 = asin((n0*sin(incd))/n1);
a2 = asin((n1*sin(a1))/n2);
a21 = asin((n2*sin(a2))/n1);
%WAVEVECTOR
k = 2*pi/range;
%THICKNESS
l1 = c/(4*n1);
l2 = c/(4*n2);
%MATRICES
A = [1 1;n0*cos(a1) -n0*cos(a1)];
B = [1 1;n1*cos(a21) -n1*cos(a21)];
C = [1 1;n2*cos(a2) -n2*cos(a2)];
D = [1 1;n3 -n3];
%PROPAGATION
X1 = [exp(1i*k*l1*n1*cos(a21)) 0;0 exp(-1i*k*l1*n1*cos(a21))];
X2 = [exp(1i*k*l2*n2*cos(a2)) 0;0 exp(-1i*k*l2*n2*cos(a2))];
%LAYER
L = X1*(B\C)*X2*(C\B);
M = (A\B)*(L^18)*X2*(L^21)*(B\D);
%REFLECTANCE
E1 = M(2,1)/M(1,1);
E2 = 100*(abs(E1)^2);
Intensity(index) = E2;
Wavelength(index) = range/1e-9;
index = index+1;
end
[Wv,In] = meshgrid(Wavelength,incd);
plot3(Wv,In,Intensity','linewidth',1)
view(-5,60); rotate3d('on');
end

Accepted Answer

Simon Chan
Simon Chan on 24 Feb 2023
Focus on the range of wavelength from 700 to 800 and find the position where abrupt change happens.
%PARAMETERS
n1 = 3.43; n2 = 2.97; n0 = 1; n3 = 3.6;
c = 767e-9; l = 0e-9; u = 3000e-9;
f = figure;
f.Visible = 'off'; % Just make it invisible here
CHARTS = tiledlayout('flow');
nexttile; grid on; grid minor; hold on
xlabel('Wavelength'); ylabel('Angle'); zlabel('Intensity')
zlim ([0 100]);
xlim ([700 800]);
WvMin = []; % Initialize WvMin to store the value of minimum wavelength
iRange = 80:-10:0; % Set iRange here
for z=1:length(iRange)
np = 20000; s = (u-l)/np;
Wavelength = zeros(1,np);
Intensity = zeros(1,np);
index = 1;
%WAVELENGTH RANGE
for range = l:s:u
incd = iRange(z)*(pi/180);
a1 = asin((n0*sin(incd))/n1);
a2 = asin((n1*sin(a1))/n2);
a21 = asin((n2*sin(a2))/n1);
%WAVEVECTOR
k = 2*pi/range;
%THICKNESS
l1 = c/(4*n1);
l2 = c/(4*n2);
%MATRICES
A = [1 1;n0*cos(a1) -n0*cos(a1)];
B = [1 1;n1*cos(a21) -n1*cos(a21)];
C = [1 1;n2*cos(a2) -n2*cos(a2)];
D = [1 1;n3 -n3];
%PROPAGATION
X1 = [exp(1i*k*l1*n1*cos(a21)) 0;0 exp(-1i*k*l1*n1*cos(a21))];
X2 = [exp(1i*k*l2*n2*cos(a2)) 0;0 exp(-1i*k*l2*n2*cos(a2))];
%LAYER
L = X1*(B\C)*X2*(C\B);
M = (A\B)*(L^18)*X2*(L^21)*(B\D);
%REFLECTANCE
E1 = M(2,1)/M(1,1);
E2 = 100*(abs(E1)^2);
Intensity(index) = E2;
Wavelength(index) = range/1e-9;
index = index+1;
end
[Wv,In] = meshgrid(Wavelength,incd);
plot3(Wv,In,Intensity','linewidth',1)
view(-5,60); rotate3d('on');
minWv = 700; % Focus on wavelength from 700 to 800
maxWv = 800;
rangelamda = Wv>700 & Wv<800; % Index for wavelength from 700 to 800
rangeWv = Wv(rangelamda); % Range of wavelength
rangeIntensity = Intensity(Wv>700 & Wv<800); % Intensity for this range of wavelength
[~,idxMin] = max(gradient(rangeIntensity)); % Find the index of having maximum gradient change
WvMin = [WvMin rangeWv(idxMin-1)]; % Store the minimum value for each iRange
end
figure(2)
plot(iRange,WvMin,'b-*');
grid on;
  3 Comments
Simon Chan
Simon Chan on 24 Feb 2023
Could you restart MATLAB and try once more? And what is the error message?
AdomPadom
AdomPadom on 24 Feb 2023
Apologies - the restart fixed it.
Thank you!

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D 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!