9

Does MATLAB have a "blackhole" or discard variable?

Say I'm doing something like:

[ rows cols ] = size( A ) ;

But I don't want rows to be stored. Is there a "black hole" variable where I can send values to die?

So the assignment would be like

[ BLACKHOLE, cols ] = size( A ) ;

Where BLACKHOLE means throw the value away and don't create a variable for it.

bobobobo
  • 64,917
  • 62
  • 258
  • 363
  • possible duplicate of [How to elegantly ignore some return values of a MATLAB function?](http://stackoverflow.com/questions/747296/how-to-elegantly-ignore-some-return-values-of-a-matlab-function) – gnovice Mar 23 '11 at 15:21
  • 1
    @gnovice: the search fu is strong with you. I'll leave my answer up for the second part for the moment. – Jonas Mar 23 '11 at 15:23

2 Answers2

13

For 2009b or later, there is the tilde sign "~"

[~,cols] = size(A);

Alternatively, in your specific case

cols = size(A,2);
Jonas
  • 74,690
  • 10
  • 137
  • 177
1

For compatibility with Matlab versions prior to 2009b you can use the following technique

[cols, cols] = size(A);

See http://blogs.mathworks.com/steve/2010/01/11/about-the-unused-argument-syntax-in-r2009b/ for example