开发者

Ignoring an output from a Matlab function [duplicate]

This question already has answers here: Closed 11 years ago.

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 memor开发者_StackOverflow中文版y 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!


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


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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜