Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
Program wont show plot
조회 수: 6 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Walter Roberson
2016년 11월 9일
편집: Walter Roberson
2016년 11월 9일
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
Steven Lord
2016년 11월 9일
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, '*')
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!