Tuesday 10 June 2014

Discarding function outputs

I wish I'd known MATLAB had... [~,Y]=F()

  • If you don't want the first return value from a function, but you want the second one, you can discard the first one with ~.
  • The main advantage is it doesn't clutter your workspace with dummy variables like temp, z, or whatever you use for unwanted variables.
  • Common examples might include:
    [~,E]=eig(X)      if you want the eigenvectors but not the eigenvalues
    [~,~,kcode] = KbCheck
            
    in psychtoolbox to get just the key codes of currently depressed keys

No comments:

Post a Comment