Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

(MATLAB) Ignoring output arguments

  1. Jul 6, 2006 #1
    Hey all,

    Suppose I have a MATLAB function that returns two (or more) output arguments, but I only care about the second one, and I do not wish to assign the value of the first one to a variable.

    What bugs me is when, for example, I solve an ODE:

    [t, x] = ode45(blablabla)

    and then MATLAB editor's automatic syntax checker tells me that the variable 't' is never used. Of course it isn't, because I don't need it :P But more importantly, it uses some memory unnessarily. So, is there any way to totally ignore that argument?

    Thank you all!
  2. jcsd
  3. Jul 6, 2006 #2


    User Avatar
    Science Advisor
    Homework Helper

    I haven't used matlab in ages, but if a function returns a vector is it not possible to pick off one component like:

  4. Jun 30, 2010 #3
    I have been wondering exactly the same thing. Haven't found a answer, though.

    Just to be clear, it is not about selecting a value of a returned vector, but selecting a specific output. It is especially annoying if I have a multiple output arguments.

    function [A,B,C,D,E,F] = myFun(inputarg)

    If I only want the last output argument F I usually just do the following
    [dummy, dummy, dummy, dummy, dummy, F] = myFun(input)

    but its ugly.
  5. Jun 30, 2010 #4
    edit the code or save as the original function without the extra arguments if it is really important to you.
  6. Jun 30, 2010 #5
    Newer versions of Matlab let you use a ~ in place of the output variables you choose to ignore. So instead of

    [dummy, dummy, dummy, dummy, dummy, F] = myFun(input),

    you could put

    [~, ~, ~, ~, ~, F] = myFun(input)

    See this blog post for more info.
  7. Jul 1, 2010 #6
    Wow, that is handy. Thanks for the link.
  8. Jul 21, 2012 #7
    Simply change the position of the variables
    [x, t] = ode45(blablabla)
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook