Why am I only getting one output when I run my Matlab function with 2+ outputs?

  • Thread starter Thread starter eurekameh
  • Start date Start date
  • Tags Tags
    Matlab
AI Thread Summary
The user is experiencing an issue with a Matlab function that is intended to return two outputs but only returns one. The function is defined correctly, but when called, it only displays the first output. To retrieve both outputs, the function should be called with the correct syntax: [apple, orange] = test2(). The user is advised to ensure they are using the correct output variable assignment format to capture all outputs. Properly calling the function will resolve the issue of receiving only one output.
eurekameh
Messages
209
Reaction score
0
I'm having trouble getting two outputs. Here's a simple example:

function [a b] = test2()
a = 2;
b = 5;

When I run the code, I only get the output of a = 2:
>>test2
ans =
2

How can I get b outted as well?
 
Physics news on Phys.org
Try a comma between a and b-- [a, b] = test2()
 
Comma is also not working.
 
Sorry, I forgot to add, call the function like so:

[apple,orange] = test2()

since it returns multiple outputs.
 
Back
Top