Plot is not working

4 ビュー (過去 30 日間)
Via
Via 2019 年 4 月 9 日
編集済み: Kevin Phung 2019 年 4 月 10 日
Hi! I don't know what I'm doing wrong here. My plot doesn't show any lines nor scatter points. What is wrong with this?
Yo= 2012500;
K= 8050000;
r= 0.71;
t= 2;
Y= (K*Yo)./((K-Yo)*exp(-r*t)+Yo);
T= 0:0.5:t;
plot (T,Y)

採用された回答

Kevin Phung
Kevin Phung 2019 年 4 月 10 日
編集済み: Kevin Phung 2019 年 4 月 10 日
Your T is a vector, and your Y is a scalar. There is no singular line because it is actually plotting all 5 points as individual line objects. check it out:
figure
Yo= 2012500;
K= 8050000;
r= 0.71;
t= 2;
Y= (K*Yo)./((K-Yo)*exp(-r*t)+Yo);
T= 0:0.5:t;
a= plot(T,Y,'ro')
The above code should plot 5 circular markers.
a will return 5 line objects.
if you ran this:
% here, both arguments are of the same size.
% All I did was repeat Y n number of times equal to the length of T
a= plot(T,repmat(Y,1,numel(T)),'r')
then a will return 1 line object, that is a line.
also, dont put a space between plot and the parentheses.
let me know if this clears your question
  3 件のコメント
Walter Roberson
Walter Roberson 2019 年 4 月 10 日
Move your assignment to T to before the assignment to Y, and in Y change the reference to t to be a reference to T
Kevin Phung
Kevin Phung 2019 年 4 月 10 日
編集済み: Kevin Phung 2019 年 4 月 10 日
^ You want Y to be a function of a vector, instead of just a constant (which is again, why you only got 1 point for 5 separate line objects).
Walter's comment:
figure
Yo= 2012500;
K= 8050000;
r= 0.71;
t= 2;
T= 0:0.5:t;
Y= (K*Yo)./((K-Yo).*exp(-r*.T)+Yo);
a= plot(T,Y,'r')
I suggest looking into the documentation for plot()

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by