Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Is there a way to check for no output arguments?

Subject: Is there a way to check for no output arguments?

From: Hoi Wong

Date: 11 Mar, 2009 10:06:20

Message: 1 of 6

My function uses varargout, but I want my function to tell if there's no
output specified (by default the first output argument goes to 'ans'
variable). nargout gives 1 no matter what I do, which makes it useless for
distinguishing between intentional output assignment.

Any suggestions?

Cheers,
Hoi

Subject: Is there a way to check for no output arguments?

From: Bruno Luong

Date: 11 Mar, 2009 10:20:03

Message: 2 of 6

"Hoi Wong" <wonghoi.ee@gmailNOSPAM.com> wrote in message <gp82es$jt6$1@fred.mathworks.com>...
> My function uses varargout, but I want my function to tell if there's no
> output specified (by default the first output argument goes to 'ans'
> variable). nargout gives 1 no matter what I do, which makes it useless for
> distinguishing between intentional output assignment.
>
> Any suggestions?
>
> Cheers,
> Hoi

Hi put this:

function varargout=nout

out=cell(nargout,1);
disp(nargout);
varargout=out;

when you run on command line;

nout
nout;

what is displayed on the screen?

Mine prints 0 twice.

Bruno

Subject: Is there a way to check for no output arguments for subsref()?

From: Hoi Wong

Date: 12 Mar, 2009 08:32:01

Message: 3 of 6

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <gp838j$bsm$1@fred.mathworks.com>...
> "Hoi Wong" <wonghoi.ee@gmailNOSPAM.com> wrote in message <gp82es$jt6$1@fred.mathworks.com>...
> > My function uses varargout, but I want my function to tell if there's no
> > output specified (by default the first output argument goes to 'ans'
> > variable). nargout gives 1 no matter what I do, which makes it useless for
> > distinguishing between intentional output assignment.
> >
> > Any suggestions?
> >
> > Cheers,
> > Hoi
>
> Hi put this:
>
> function varargout=nout
>
> out=cell(nargout,1);
> disp(nargout);
> varargout=out;
>
> when you run on command line;
>
> nout
> nout;
>
> what is displayed on the screen?
>
> Mine prints 0 twice.
>
> Bruno

I just noticed that the weird behavior I described only happens to overloaded operators in subsref(). I have a sparse_cell called 'deviceHash' and if I call

deviceHash{1, 4096}

nargout will show up as 1 even if my subsref doesn't have anything else in it, lilke:

function varargout = subsref(a,s)
    nargout
end

Any advice?

Thanks for your help.

-- Hoi

Subject: Is there a way to check for no output arguments for subsref()?

From: Bruno Luong

Date: 12 Mar, 2009 09:04:04

Message: 4 of 6

"Hoi Wong" <wonghoi.ee@gmailNOSPAM.com> wrote in message <gpaha1$chc$1@fred.mathworks.com>...

>
> I just noticed that the weird behavior I described only happens to overloaded operators in subsref(). I have a sparse_cell called 'deviceHash' and if I call
>
> deviceHash{1, 4096}
>
> nargout will show up as 1 even if my subsref doesn't have anything else in it, lilke:
>
> function varargout = subsref(a,s)
> nargout
> end
>
> Any advice?
>

I have read in a book (A Guide to MATLAB Object-oriented) overloaded subsref might have "wrong" nargout, propably because it is called by another layer from OO engine.

I have bump to the same issue recently, and can't find satisfied solution.

Bruno

Subject: Is there a way to check for no output arguments for subsref()?

From: Bruno Luong

Date: 12 Mar, 2009 09:04:04

Message: 5 of 6

"Hoi Wong" <wonghoi.ee@gmailNOSPAM.com> wrote in message <gpaha1$chc$1@fred.mathworks.com>...

>
> I just noticed that the weird behavior I described only happens to overloaded operators in subsref(). I have a sparse_cell called 'deviceHash' and if I call
>
> deviceHash{1, 4096}
>
> nargout will show up as 1 even if my subsref doesn't have anything else in it, lilke:
>
> function varargout = subsref(a,s)
> nargout
> end
>
> Any advice?
>

I have read in a book (A Guide to MATLAB Object-oriented) overloaded subsref might have "wrong" nargout, propably because it is called by another layer from OO engine.

I have bump to the same issue recently, and can't find satisfied solution.

Bruno

Subject: Is there a way to check for no output arguments for subsref()?

From: Hoi Wong

Date: 28 Mar, 2009 22:31:01

Message: 6 of 6

Thanks. I filed a request to Mathworks. The book makes the argument more convincing.

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <gpaj64$e5i$1@fred.mathworks.com>...
> "Hoi Wong" <wonghoi.ee@gmailNOSPAM.com> wrote in message <gpaha1$chc$1@fred.mathworks.com>...
>
> >
> > I just noticed that the weird behavior I described only happens to overloaded operators in subsref(). I have a sparse_cell called 'deviceHash' and if I call
> >
> > deviceHash{1, 4096}
> >
> > nargout will show up as 1 even if my subsref doesn't have anything else in it, lilke:
> >
> > function varargout = subsref(a,s)
> > nargout
> > end
> >
> > Any advice?
> >
>
> I have read in a book (A Guide to MATLAB Object-oriented) overloaded subsref might have "wrong" nargout, propably because it is called by another layer from OO engine.
>
> I have bump to the same issue recently, and can't find satisfied solution.
>
> Bruno

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us