Making function output vector instead of value

1 回表示 (過去 30 日間)
Alexandru Bortea
Alexandru Bortea 2017 年 4 月 16 日
コメント済み: Alexandru Bortea 2017 年 4 月 17 日
I was working on a function that is using a vector v to decide which gear ratio to use. However, when I get the result from the function it only outputs one value although the velocity vector values go higher than the if conditions.
function gr = gearratio_fun(v)
if v > 36.96
gr = 4.0718571; %3rd gear
elseif v > 30.097
gr = 5.0005263; %2nd gear
else
gr = 7.8119333; %1st gear
end
  2 件のコメント
the cyclist
the cyclist 2017 年 4 月 16 日
Can you please give an example of an input v, along with
  • the output you see from the function, and
  • the output you expect or want from the function
Alexandru Bortea
Alexandru Bortea 2017 年 4 月 17 日
I have attached v below with all the values that it goes through. For each value of v I would like to have a gr value assigned, so a same size vector as v. However when I run the function, the output it gives for the attached v is gr = 7.8119

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

採用された回答

Matt J
Matt J 2017 年 4 月 17 日
function gr = gearratio_fun(v)
gr=v;
gr(:)=7.8119333;
gr(v > 30.097 ) = 5.0005263;
gr(v > 36.96 ) = 4.0718571;
  1 件のコメント
Alexandru Bortea
Alexandru Bortea 2017 年 4 月 17 日
That is exactly what I wanted! Thank you very much!

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by