1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Matlab - Having 2+ outputs

  1. Nov 14, 2012 #1
    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:
    ans =

    How can I get b outted as well?
  2. jcsd
  3. Nov 14, 2012 #2


    User Avatar
    Gold Member

    Try a comma between a and b-- [a, b] = test2()
  4. Nov 14, 2012 #3
    Comma is also not working.
  5. Nov 14, 2012 #4


    User Avatar
    Gold Member

    Sorry, I forgot to add, call the function like so:

    [apple,orange] = test2()

    since it returns multiple outputs.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook