Info
This question is closed. Reopen it to edit or answer.
Program wont show plot
6 views (last 30 days)
Show older comments
Hello, my program wont show a plot when i run my code, only an empty figure box. Can someone help?
n0 = 1; %air
n1 = 1.4; %layer 1
n2 = 2; %layer 2
n3 = 3.5; %silicon
L0 = 650*10^(-9); %centre wavelength
L1 = 200*10^(-9): 5*10^(-9): 2200*10^(-9); %lambda from 200nm to 2200nm
x = ((pi./2).*(L0./L1)); %layer phase thickness
r01 = ((n0 - n1)./(n0 + n1)); %reflection coefficient 01
r12 = ((n1 - n2)./(n1 + n2)); %reflection coefficient 12
r23 = ((n2 - n3)./(n2 + n3)); %reflection coefficient 23
t01 = ((2.*n0)./(n0 + n1)); %transmission coefficient 01
t12 = ((2.*n1)./(n1 + n2)); %transmission coefficient 12
t23 = ((2.*n2)./(n2 + n3)); %transmission coefficient 23
Q1 = [1 r01; r01 1]; %Matrix Q1
Q2 = [1 r12; r12 1]; %Matrix Q2
Q3 = [1 r23; r23 1]; %Matrix Q3
for i = 1:length(x)
P = [exp(j.*x(i)) 0; 0 exp(-j.*x(i))]; %General Matrix P
T = ((1./(t01.*t12.*t23)).*(Q1*P*Q2*P*Q3)); %Transmission
T11 = T(1,1); %T11 value
T21 = T(2,1); %T21 value
R = ((abs(T21./T11))^2).*100; %Percent reflectivity
plot(L1,R)
end
0 Comments
Answers (1)
Walter Roberson
on 9 Nov 2016
Edited: Walter Roberson
on 9 Nov 2016
You are only plotting one point at a time, and you did not specify a marker. When you plot() the default is to not display a marker. Also, each time you plot you overwrite everything you have plotted before.
You need to change to
plot(L1, R, '*')
hold on
1 Comment
Steven Lord
on 9 Nov 2016
Or assemble a vector of values of R, one value per loop iteration, then plot that vector after the loop is complete.
R = zeros(size(x)); % Preallocate
for i = 1:length(x)
...
R(i) = ...
end
plot(L1, R, '*')
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!