while plotting the graph ,it appears blank. How to solve this problem?

My code is as below
f=[1,2,3,4,5,6,7,8,9,10];
l=length(f);
for i=1:l
t=1/0.4521;
z=3.68*10^(-7)*(t)^(1/2)*(2*3.14*f(i))^0.5;
plot(f(i),z);
end

 採用された回答

Thomas
Thomas 2012 年 4 月 26 日

1 投票

Try saving z as a vector and plotting it outside the loop..
f=[1,2,3,4,5,6,7,8,9,10];
t=1/0.4521;
l=length(f);
for i=1:l
z(i)=3.68*10^(-7)*(t)^(1/2)*(2*3.14*f(i))^0.5;
end
plot(f,z);

4 件のコメント

Walter Roberson
Walter Roberson 2012 年 4 月 26 日
Though I am puzzled as to why "t" was not set _before_ the loop.
Thomas
Thomas 2012 年 4 月 26 日
true 't' can be set before starting the loop. did not pay attention to it.. Thanks.. :)
Isha Deshpande
Isha Deshpande 2012 年 4 月 28 日
Hi Thomas, thanks for solving my issue
i am getting graph properly, my code now looks as below
{f=1:100;
t=1/0.4521;
for i=1:100
z(i)=(3.68*10^(-7)*(t)^(1/2)*(2*3.14*f(i))^0.5);
end
loglog(f,z)}
Walter Roberson
Walter Roberson 2012 年 4 月 28 日
You should be able to simplify the code by eliminating the loop and using
z = 3.68E-7 * sqrt(t) * sqrt(2 * pi) * sqrt(f);
or if you want to reduce sqrt() calls,
z = 3.68E-7 * sqrt(2 * pi * t * f);

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で 2-D and 3-D Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by