Plotting functions using loop

조회 수: 2 (최근 30일)
mohammed shapique
mohammed shapique 2020년 9월 10일
댓글: mohammed shapique 2020년 9월 10일
lambda=1
gamma1=0.3
n=0:1:15;
for i=1:15
n=0+i;
P1(n)=((lambda.^n)/(lambda+gamma1).^(n+1));
end
After running this program, in the command box i typed plot(P1(:)). The curve starts from 1 and not from zero. please help me to find the mistake in the program.
  댓글 수: 1
Steven Lord
Steven Lord 2020년 9월 10일
When you call plot with one vector input that input is used as the y data. The corresponding x data is the indices of the elements in the vector and array indices in MATLAB start at 1. See the Description section of the plot function's documentation page for more information.
Asad (Mehrzad) Khoddam has given you a vectorized solution that calls plot with two inputs.

댓글을 달려면 로그인하십시오.

채택된 답변

Asad (Mehrzad) Khoddam
Asad (Mehrzad) Khoddam 2020년 9월 10일
lambda=1;
gamma1=0.3;
n=0:1:15;
P1 = (lambda.^n)./(lambda+gamma1).^(n+1));
plot(n, P1);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by