Outputs of a function
1 回表示 (過去 30 日間)
古いコメントを表示
Hello! I'm currently writing functions that take input, and need to return a ouput to be used by a later function. However, in the function programming, I know that I have many different variables that I'm defining in order to do the function that I need. So when I try to get the function to do an output argument (i.e. X = function(input);), it gives me the error that I have too many output arguments.
Is there a way that I can label (inside the function itself) the one ouput I want so that it only sees that variable as the correct output?
0 件のコメント
採用された回答
tlawren
2012 年 6 月 26 日
Is your function declaration correct? For example, the following two functions are declared to return one and two variables respectively. Both take in three inputs.
function x = test1(a,b,c)
function [x,y] = test2(a,b,c)
If your function declaration looks like this
function test1(a,b,c)
and you try to get outputs from it with
x = test1(in1, in2, in3)
in your other code, then you will get a "Too many output arguments" error.
0 件のコメント
その他の回答 (1 件)
Jaden
2012 年 6 月 26 日
1 件のコメント
Walter Roberson
2012 年 6 月 26 日
Any variable whose name does not appear on the left side of the "function" statement (and which is not a global or nested variable) will be deleted when the function exit, so it is not a problem to create as many variables as you need to calculate the values that you want to return.
参考
カテゴリ
Help Center および File Exchange で Tables についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!