-1

Possible Duplicate:
How to elegantly ignore some return values of a MATLAB function?

I have a Matlab function with two outputs. Sometimes I use both outputs.

function [output1 output2] = myFunction(input)
[a b] = myFunction(input);

Other times I only need output1 and don't want to waste memory assigning output2

a = myFunction(input);

However, I can't figure out a simple way to give the reverse scenario (only need output2 and don't want to waste memory assigning output1). I thought it would be something like

[~ b] = myFunction(input)

but that doesn't seem to work. Anybody have suggestions for a quick solution? Thanks for your help!

Community
  • 1
  • 1
yy08
  • 41
  • 3

2 Answers2

2

It's [~, b], not [~ b]. The comma is missing.

Phonon
  • 12,549
  • 13
  • 64
  • 114
0

the object will be created inside myFunction either way, unless your input has a way to prevent the creation. If you can prevent the creation internally, you can modify myFunction to return a cell array or other structure, from which you can decide which elements to keep. If your concern is that [dontwant b] is wasting matlab memory by holding dontwant, then you might want to delete dontwant from your workspace by calling

clear dontwant;
BlessedKey
  • 1,615
  • 1
  • 10
  • 16