Why my plot doesn't show the line?

1 次查看(过去 30 天)
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