(MATLAB) Ignoring output arguments

  • MATLAB
  • Thread starter juef
  • Start date
  • #1
27
0
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!
 

Answers and Replies

  • #2
shmoe
Science Advisor
Homework Helper
1,992
1
I haven't used matlab in ages, but if a function returns a vector is it not possible to pick off one component like:

x=ode45(blablabla)[2]
 
  • #3
30
0
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)
...​
end

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.
 
  • #4
341
0
edit the code or save as the original function without the extra arguments if it is really important to you.
 
  • #5
166
0
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.
 
  • #6
341
0
Wow, that is handy. Thanks for the link.
 
  • #7
1
0
Simply change the position of the variables
[x, t] = ode45(blablabla)
 

Related Threads on (MATLAB) Ignoring output arguments

  • Last Post
Replies
1
Views
13K
  • Last Post
Replies
1
Views
2K
Replies
1
Views
3K
Replies
2
Views
4K
Replies
2
Views
147K
  • Last Post
Replies
1
Views
1K
Replies
1
Views
9K
Replies
2
Views
3K
Replies
1
Views
2K
Top