e.g. I have a function [A, B, C] = foo(vargin)
. Now I ONLY want the second return value B. Is there any way to get only B without keeping A and C in place or modifying my function code.
Asked
Active
Viewed 265 times
2 Answers
8
The best way is this: [~, B] = foo(vargin)
. Works since Matlab 2009b I think

Dan
- 45,079
- 17
- 88
- 157
-
3(Valid for matlab 2010+ I think) – Hugh Nolan Jul 23 '13 at 14:26
-
You type quicker than me :-) – am304 Jul 23 '13 at 14:27
-
2@am304 That's because you wasted precious time typing that extraneous second `~` ;) but +1 for you anyway – Dan Jul 23 '13 at 14:28
-
Oh, come on. It is NOT that messy. In fact, there are several ways to do this trivially even without the ~. – Jul 23 '13 at 14:54
-
@woodchips I'll remove that sentence if it upsets you. Perhaps you can post the alternatives? – Dan Jul 23 '13 at 14:55
-
http://stackoverflow.com/questions/747296/how-to-elegantly-ignore-some-return-values-of-a-matlab-function – Jul 23 '13 at 14:56
5
[~,B,~] = foo(vargin)
I think it doesn't work in older versions of MATLAB, but can't remember for sure when ~
was introduced.

am304
- 13,758
- 2
- 22
- 40