HELP! My for loop code won't produce a line on the graph I plot

1 回表示 (過去 30 日間)
Aaron Clewer
Aaron Clewer 2020 年 3 月 10 日
コメント済み: ME 2020 年 3 月 10 日
When I run my code, results will appear but my results just won't show on the graph:
K = 1
i = sqrt(-1);
n=0;
for w = 0.1:1000
n=n+1;
A(n) = w;
G(n) = K/((i*w)*((i*w)+1.71)*((i*w)+100));
end
M(n) = abs(G(n));
F(n) = 20*log(M(n));
semilogx(w,F)

回答 (2 件)

Ameer Hamza
Ameer Hamza 2020 年 3 月 10 日
編集済み: Ameer Hamza 2020 年 3 月 10 日
You were just plotting a single point. Check the indexing of variables after the for loop.
K = 1;
i = sqrt(-1);
n=0;
W = 0.1:1000;
for w = W
n=n+1;
A(n) = w;
G(n) = K/((i*w)*((i*w)+1.71)*((i*w)+100));
end
M = abs(G);
F = 20*log(M);
semilogx(W,F)
  2 件のコメント
Aaron Clewer
Aaron Clewer 2020 年 3 月 10 日
This helped so much. 1000 thank yous
Ameer Hamza
Ameer Hamza 2020 年 3 月 10 日
Glad to be of help.

サインインしてコメントする。


ME
ME 2020 年 3 月 10 日
I'm not 100% sure but I'd guess you want the last line to be:
semilogx(A,F)
because otherwise everything is plotting at the same value on the x-axis.
  2 件のコメント
Aaron Clewer
Aaron Clewer 2020 年 3 月 10 日
This ends up giving me the same value at the x-axis as the previous code. Thank you for the help though
ME
ME 2020 年 3 月 10 日
Plots over the whole range of the x-axis for me. I guess the issue is that the line is right along the edge of the figure window. If you change the view of the axes or the axes limits then you'll be able to see the line.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeTitle についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by