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
Click For Summary

Discussion Overview

The discussion revolves around a user experiencing issues with obtaining multiple outputs from a MATLAB function. The focus is on the syntax and method of calling the function to retrieve both outputs.

Discussion Character

  • Technical explanation

Main Points Raised

  • One participant describes their function and notes that only one output is being returned when they expect two.
  • Another participant suggests using a comma between the outputs in the function call.
  • A subsequent reply indicates that using a comma did not resolve the issue.
  • A later reply clarifies that the function should be called with the syntax [apple, orange] = test2() to correctly retrieve both outputs.

Areas of Agreement / Disagreement

Participants have not reached a consensus on the solution, as there are conflicting suggestions regarding the correct syntax for obtaining multiple outputs.

Contextual Notes

There may be missing assumptions about the function's definition or the context in which it is being called, which could affect the outputs.

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.
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
2K
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 10 ·
Replies
10
Views
2K
Replies
1
Views
2K
  • · Replies 13 ·
Replies
13
Views
3K