필터 지우기
필터 지우기

Why my plot doesn't show the line?

조회 수: 1 (최근 30일)
Ray Malifalitiko
Ray Malifalitiko 2020년 11월 15일
답변: Setsuna Yuuki. 2020년 11월 15일
I'm very new with this program. Here is my code. Am I missing something? Could someone fix it and explain to me, thank you.
c = 3*10^8;
f0 = 10^9;
d0=10^3;
for i = 1:100
f1 = 1/(10*i/(c+10));
fd = f1-f0;
plot(i,fd)
hold on
end

채택된 답변

Star Strider
Star Strider 2020년 11월 15일
If you must use a loop, you need to subscript ‘f1’:
f1(i) = 1/(10*i/(c+10));
However a loop is not necessary. Using element-wise operations, this works:
c = 3*10^8;
f0 = 10^9;
d0=10^3;
i = 1:100;
f1 = 1./(10*i/(c+10));
fd = f1-f0;
plot(i,fd)
See Array vs. Matrix Operations for details.

추가 답변 (1개)

Setsuna Yuuki.
Setsuna Yuuki. 2020년 11월 15일
You can use this example:
i = linspace(0,100,1000);
c = 3*10^8;
f0 = 10^9;
d0=10^3;
f1 = 1./(10*i/(c+10));
fd = f0-f1;
plot(i,fd,'linewidth',2)
xlim([0 10])

카테고리

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