フィルターのクリア

Why Matlab does not plot "for loop" generated vector?

1 回表示 (過去 30 日間)
Anne
Anne 2020 年 2 月 16 日
コメント済み: Walter Roberson 2020 年 2 月 19 日
I am quite a beginner and after hours of googling I just could not figure out why Matlab does not plot what needed. I can see only a blank.
My script is:
c = 7;
n=12;
for i = 0:1:n
u=i;
p_u = (2.3/c)*((u/c)^1.3)*exp(-(u/c)^2.3);
hours =8760*p_u*(1-0.09);
hold on;
plot(u, hours)
end
Thank you in advance!

採用された回答

David Hill
David Hill 2020 年 2 月 16 日
Best to use arrays/vectors.
c=7;
n=12;
u=0:.1:n;
hours = (2.3/c)*((u/c).^1.3).*exp(-(u/c).^2.3)*(1-0.09)*8760;
plot(u,hours)
  4 件のコメント
Rik
Rik 2020 年 2 月 18 日
You can define u however you like. That is the benefit of writing code like this.
Anne
Anne 2020 年 2 月 18 日
I found a mistake. I didn't see that there was a dot.

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

その他の回答 (1 件)

Anne
Anne 2020 年 2 月 18 日
It is a pity that when I need to use Matlab fast, then I will have errors all the time.
This code is giving 1x11176 vector for power and I don't know why. It should be 1x151 vector. because i=0:0.1:15 wll be vector with 151 elements. It worked well when I chose i=0:15
n=15;
uu=0:0.1:n;
u_cutin=1;
u_N=3;
u_cutout=7;
ii=1
for i=0:0.1:n
if i<u_cutin
power1(ii)=0
elseif i>=u_N && i<=u_cutout
power1(ii)=0.42*0.718*0.5*1.2*pi*((38/2)^2)*u_N^3
elseif i>u_cutout
power1(ii)=0
else
power1(ii)=0.42*0.718*0.5*1.2*pi*((38/2)^2)*i^3
end
ii=ii+i*10
end
plot(uu,power1)
  1 件のコメント
Walter Roberson
Walter Roberson 2020 年 2 月 19 日
You do not initialize power in this code.

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by