Azzera filtri
Azzera filtri

Why my plot doesn't show the line?

1 visualizzazione (ultimi 30 giorni)
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

Risposta accettata

Star Strider
Star Strider il 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.

Più risposte (1)

Setsuna Yuuki.
Setsuna Yuuki. il 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])

Categorie

Scopri di più su Line Plots in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by