Setting the amount of data points before plotting

6 ビュー (過去 30 日間)
N/A
N/A 2014 年 1 月 15 日
コメント済み: N/A 2014 年 1 月 15 日
As a novice to Matlab, I am having great difficulty with the simplest of things. My current code is like this:
function Q = hydrogenusage(P)
Q= (120*P)-(P.^2);
plot(P,Q)
xlabel('Power')
ylabel('Usage')
title('Hydrogen usage')
axis([0 120 0 4000])
grid on
end
I currently have to enter the following: hydrogenusage(0:large number) to make this work properly. But I want to edit this so I just have to enter 'hydrogenusage' and it gives me my plot. For this the amount of data points (the 0 to large number) should be specified before (therefore I tried adding the axis but that only setted the axis) in the script of the program.
Who knows what to do?

採用された回答

Amit
Amit 2014 年 1 月 15 日
編集済み: Amit 2014 年 1 月 15 日
How about
function hydrogenusage
P = 0:1:4000;
Q= (120*P)-(P.^2);
plot(P,Q)
xlabel('Power')
ylabel('Usage')
title('Hydrogen usage')
axis([0 120 0 4000])
grid on
end
  1 件のコメント
N/A
N/A 2014 年 1 月 15 日
It works! Thank you so much!

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by