Why my plot doesn't show the line?

3 views (last 30 days)
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

Accepted Answer

Star Strider
Star Strider on 15 Nov 2020
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.

More Answers (1)

Setsuna Yuuki.
Setsuna Yuuki. on 15 Nov 2020
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])

Categories

Find more on Line Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!