Effacer les filtres
Effacer les filtres

Why my plot doesn't show the line?

1 vue (au cours des 30 derniers jours)
Ray Malifalitiko
Ray Malifalitiko le 15 Nov 2020
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

Réponse acceptée

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

Plus de réponses (1)

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

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by