Matlab "too many output arguments"

I have a function I created that takes 20 inputs, and is supposed to output 4 outputs after it uses simulink and does all the code in the function.
Also as a note, the 4 output types that I'm trying to output are different. 2 of the outputs are arrays, and the other 2 outputs are signed integers, so whole numbers.
I currently have the 1st function line as: function [w, x, y, z] = myfoo(x1, x2, ..., x20)
But I also wrote a script for testing different values and I just call on the function and pass it the 20 inputs I defined.
but for some reason when I try to get it to output my 4 values using: [w, x, y, z] = myfoo(x1, x2, ..., x20)
It gives me the error of "too many output arguments" but I don't know why.

4 Kommentare

sixwwwwww
sixwwwwww am 24 Okt. 2013
Can you show how you are calling the function? and how you are passing inputs to it?
Gilmar
Gilmar am 24 Okt. 2013
The way I'm passing inputs is by declaring them in the script and hard-coding, basically I manually set the values in my script. So I have this setup:
x1=2;
x2=72;
x20= 88;
I do that same structure a total of 20 times, and the last line of the script is basically this:
[w, x, y, z] = myfoo(x1, x2,...,x20);
I can tell it does call the function because I get all my plot graphs but its not returning my outputs.
Also the actual header line I have for my function is more like:
function [w, x_out, y_out, mod_out] = myfoo(x1, x2, ..., x20)
I don't think having the underscore character causes a problem.
Azzi Abdelmalek
Azzi Abdelmalek am 24 Okt. 2013
Now, can you show your code?
Gilmar
Gilmar am 24 Okt. 2013
I would, but I can't show you my code, which is why I've been trying to put in as much tidbits as I can. I'm not allowed to show my code to others.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

sixwwwwww
sixwwwwww am 24 Okt. 2013

1 Stimme

Dear Gilmar, I wrote a sample function which takes 20 inputs and gives 4 outputs as below:
function [w, x, y, z] = myfoo(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19, x20)
w = x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19 + x20;
x = x1 - x2 - x3 - x4 - x5 - x6 - x7 - x8 - x9 - x10 - x11 - x12 - x13 - x14 - x15 - x16 - x17 - x18 - x19 - x20;
y = x1 * x2 * x3 * x4 * x5 * x6 * x7 * x8 * x9 * x10 * x11 * x12 * x13 * x14 * x15 * x16 * x17 * x18 * x19 * x20;
z = x1 + x2 - x3 - x4 * x5 * x6 + x7 + x8 - x9 - x10 * x11 * x12 + x13 + x14 - x15 - x16 * x17 * x18 + x19 + x20;
end
And I called this function as below:
[b, c, d, e] = myfoo(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
with a1, a2, ... , a20 = 1, 2, ... , 20 and I didn't got any error. So maybe you can check it and find out maybe you are allocating some value to one of your output arguments. Without code the error is difficult to sort out. I hope it helps. Good luck!

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 24 Okt. 2013

Beantwortet:

am 24 Okt. 2013

Community Treasure Hunt

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

Start Hunting!

Translated by