No Plotting Done In Function With Changing Variables
조회 수: 2 (최근 30일)
이전 댓글 표시
I am trying to plot a function that varies as a function of angular values. I have followed example code from many here and can get the code to run, but the resultant plot is empty. Can anyone spot what kind of issue I'm having? Gamma seems to reach the value of 6 before quitting on me
ncont=3.24;
kcont=4.28;
step=pi/180
limit=2*pi
for gamma = 0:step:limit
num1=(((ncont*cos(gamma))-1)^2)+((kcont^2)*cos(gamma)^2);
num2=((ncont-cos(gamma))^2)+kcont^2;
den1=(((ncont*cos(gamma))-1)^2)+((kcont^2)*cos(gamma)^2);
den2=((ncont+cos(gamma))^2)+kcont^2;
abs=1-(0.5*((num1/den1)+(num2/den2)));
plot(gamma,abs);
end
댓글 수: 0
채택된 답변
DGM
2022년 2월 13일
편집: DGM
2022년 2월 13일
The problem is how you're specifying the linetype and when you're doing the plotting. Since you're plotting each point one at a time, there are 361 individual plot objects consisting of no line (because each is only one point) and no marker type.
You can specify a marker type and get a pseudoline
ncont=3.24;
kcont=4.28;
step=pi/180;
limit=2*pi;
for gamma = 0:step:limit
num1=(((ncont*cos(gamma))-1)^2)+((kcont^2)*cos(gamma)^2);
num2=((ncont-cos(gamma))^2)+kcont^2;
den1=(((ncont*cos(gamma))-1)^2)+((kcont^2)*cos(gamma)^2);
den2=((ncont+cos(gamma))^2)+kcont^2;
abs=1-(0.5*((num1/den1)+(num2/den2)));
plot(gamma,abs,'k.'); hold on
end
Or you can save the results and plot them outside the loop.
ncont=3.24;
kcont=4.28;
step=pi/180;
limit=2*pi;
gamma = 0:step:limit;
absv = zeros(size(gamma));
for k = 1:numel(gamma)
num1=(((ncont*cos(gamma(k)))-1)^2)+((kcont^2)*cos(gamma(k))^2);
num2=((ncont-cos(gamma(k)))^2)+kcont^2;
den1=(((ncont*cos(gamma(k)))-1)^2)+((kcont^2)*cos(gamma(k))^2);
den2=((ncont+cos(gamma(k)))^2)+kcont^2;
absv(k)=1-(0.5*((num1/den1)+(num2/den2)));
end
figure
plot(gamma,absv)
Of course, the loop isn't necessary either.
ncont=3.24;
kcont=4.28;
step=pi/180;
limit=2*pi;
gamma = 0:step:limit;
num1=(((ncont*cos(gamma))-1).^2)+((kcont^2)*cos(gamma).^2);
num2=((ncont-cos(gamma)).^2)+kcont^2;
den1=(((ncont*cos(gamma))-1).^2)+((kcont^2)*cos(gamma).^2);
den2=((ncont+cos(gamma)).^2)+kcont^2;
absv=1-(0.5*((num1./den1)+(num2./den2)));
figure
plot(gamma,absv)
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Object Identification에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!