MATLAB Answers

0

Anyone that can find what is wrong about the function?

Jenny Andersen さんによって質問されました 2019 年 11 月 17 日 14:32
最新アクティビティ Stephen Cobeldick
さんによって コメントされました 2019 年 11 月 19 日 7:59
It says " Not enough input values" but I can not see which values I have missed? Can you?
Skärmavbild 2019-11-17 kl. 15.27.54.png

  3 件のコメント

Stephen Cobeldick
2019 年 11 月 17 日 15:11
Are you calling the function in the command window (or from another location, e.g. from another script or function) with two input arguments (as you should be doing) or are you just clicking the big green "Run" button (which unless you have set it up properly, will not provide any input arguments to your function) ?
Jenny Andersen 2019 年 11 月 18 日 20:09
Hi, and thanks for your reply. I have tried to call the function in the command window with two input arguments and that works fine. But if I want to be able to run the function (by clicking "Run"), how do I need to change my function to be able to achive this?
Stephen Cobeldick
2019 年 11 月 19 日 7:59
"But if I want to be able to run the function (by clicking "Run"), how do I need to change my function to be able to achive this?"
You can either:
  1. write your function to have default values when input arguments are not supplied, or
  2. set up the "Run" button to provide specific input values when you call that function.
Which would you prefer?

サインイン to comment.

タグ

1 件の回答

Adam Danz
回答者: Adam Danz
2019 年 11 月 18 日 21:24
編集済み: Adam Danz
2019 年 11 月 18 日 21:25
 採用された回答

"if I want to be able to run the function (by clicking "Run"), how do I need to change my function to be able to achive this?"
Sometimes functions can have default inputs when they are missing from the function-call. Here is an example of how to define default inputs to both of your input variables. The default inputs are defined with the function call is missing the inputs or if the inputs are empty. Sometimes it's good to incude warnings when assigning default inputs so you know when an input was missing. You can remove the warnings in this example, of course.
function [v2, v3] = OrtoVektorFunction(w3, w2)
% Default inputs
if nargin < 1 || isempty(w3)
w3 = 0;
warning('Default input used.')
end
if nargin < 2 || isempty(w2)
w2 = 1;
warning('Default input used.')
end
% Continue with code....

  0 件のコメント

サインイン to comment.



Translated by