How to use inputs within a function?
古いコメントを表示
function Discriminant (a)
a = input('Enter the value of a: ');
b = a*2
fprintf('The value of b is: %i', b)
end
This is an example of the code I am going to use. I want there to be a prompt for a user to enter a value of a, and in turn, my function will use that value of a in the formula, and print the value of b.
3 件のコメント
Torsten
2024 年 2 月 9 日
Because of the numerous basic questions from your side, I suggest you invest two hours of your time to take the MATLAB online course free of costs:
Then most of your questions will get answered automatically.
TheSaint
2024 年 2 月 9 日
Regardless of the fact that you are using functions, have a look at your code:
function Discriminant (a)
a = input('Enter the value of a: ');
You define a somehow (as a function input... but really it does not matter how, all that matters is that it is defined because this basic principal applies to all variables all of the time). The you redefine a to be something else (using INPUT, but again it does not really matter how you do this).
If you want to use the original a that you defined, then don't redefine a to be something else.
INPUT... needs to be unlearned one day.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Discriminant Analysis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!