フィルターのクリア

I am using function to calculate an expression.

1 回表示 (過去 30 日間)
rihan jericho
rihan jericho 2018 年 1 月 29 日
コメント済み: Jan 2018 年 1 月 31 日
for example, function y=g(x) y=5+x end This gets my job done when one argument is passed, for example g(5). But what i want to do is , when i put g(5, 'v'), i want it to execute a different formula instead y=5+x. On this occasion, i want it to execute y=5+x.^2 . How can i do this. Any idea please?
  1 件のコメント
Jan
Jan 2018 年 1 月 31 日
@rihan jericho, Md Epu, Joe Raihan: Please stop deleting your question, after you got an answer.

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

採用された回答

Birdman
Birdman 2018 年 1 月 29 日
function y=g(x,v)
if nargin==1
y=5+x;
elseif nargin==2
y=5+x.^2;
end
end
When you call from command line like
g(3)
it returns
8
but when you call like
g(3,'V')
it returns
14

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by