f



One or more output arguments not assigned during call to "varargout".

I googled this error message and can not even find one that exactly match the whole sentence, am I the only person who get the error?

I use Matlab 2015b to run a simulation, and I got this error message randomly during 1 of multiple same simulations. 

My function is like the following:

[varargout] = function MyFunction(var1, var2, varargin)

  output1 = [xxx];
  output2 = [xxx];
  output3 = [xxx];
  ...
  varargout{1} = output1;

  if nvargin > 2
    varargout{1} = output2, 
    varargout{2} = output3;
  end
end

I got the following error:
One or more output arguments not assigned during call to "varargout".

Error in PowerFlowCalculation (line 51)
        [x, y] = MyFunction(var1, var2, 'xxx');
Can anyone give me hint? I really appreciate it, thank you!
0
MWei
9/29/2015 10:19:03 PM
comp.soft-sys.matlab 211264 articles. 26 followers. lunamoonmoon (257) is leader. Post Follow

4 Replies
1318 Views

Similar Articles

[PageSpeed] 10

"MWei" <mingkui_wei@hotmail.com> wrote in message <muf2on$pbo$1@newscl01ah.mathworks.com>...
> I googled this error message and can not even find one that exactly match the whole sentence, am I the only person who get the error?
> 
> I use Matlab 2015b to run a simulation, and I got this error message randomly during 1 of multiple same simulations. 
> 
> My function is like the following:
> 
> [varargout] = function MyFunction(var1, var2, varargin)
> 
>   output1 = [xxx];
>   output2 = [xxx];
>   output3 = [xxx];
>   ...
>   varargout{1} = output1;
> 
>   if nvargin > 2
>     varargout{1} = output2, 
>     varargout{2} = output3;
>   end
> end
> 
> I got the following error:
> One or more output arguments not assigned during call to "varargout".
> 
> Error in PowerFlowCalculation (line 51)
>         [x, y] = MyFunction(var1, var2, 'xxx');
>
> Can anyone give me hint? I really appreciate it, thank you!

What is nvargin?  I don't see it defined. I would have expected code something like this:

   if nargout < 2
       varargout{1} = output1;
   elseif nargout == 2
       varargout{1} = output2, 
       varargout{2} = output3;
   else
       error('Too many outputs');
   end


James Tursa
0
James
9/30/2015 5:38:03 AM

"MWei" <mingkui_wei@hotmail.com> wrote in message 
news:muf2on$pbo$1@newscl01ah.mathworks.com...
> I googled this error message and can not even find one that exactly match 
> the whole sentence, am I the only person who get the error?
>
> I use Matlab 2015b to run a simulation, and I got this error message 
> randomly during 1 of multiple same simulations.
> My function is like the following:
>
> [varargout] = function MyFunction(var1, var2, varargin)

I assume this is a copy/paste error and that your function actually starts:

function varargout = MyFunction(var1, var2, varargin)

>  output1 = [xxx];
>  output2 = [xxx];
>  output3 = [xxx];
>  ...
>  varargout{1} = output1;
>
>  if nvargin > 2

This smells fishy. nvargin looks like it is probably a variable containing 
the value returned by the NARGIN function or perhaps the value 
length(varargin). Why are you only assigning a value to the second _output_ 
based on the number of _inputs_?

if nargout > 1
    varargout{2} = output3;
end

*snip*

-- 
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on 
http://www.mathworks.com 

0
Steven
10/1/2015 3:30:07 PM
"James Tursa" wrote in message <mufsfr$kl5$1@newscl01ah.mathworks.com>...
> "MWei" <mingkui_wei@hotmail.com> wrote in message <muf2on$pbo$1@newscl01ah.mathworks.com>...
> > I googled this error message and can not even find one that exactly match the whole sentence, am I the only person who get the error?
> > 
> > I use Matlab 2015b to run a simulation, and I got this error message randomly during 1 of multiple same simulations. 
> > 
> > My function is like the following:
> > 
> > [varargout] = function MyFunction(var1, var2, varargin)
> > 
> >   output1 = [xxx];
> >   output2 = [xxx];
> >   output3 = [xxx];
> >   ...
> >   varargout{1} = output1;
> > 
> >   if nvargin > 2
> >     varargout{1} = output2, 
> >     varargout{2} = output3;
> >   end
> > end
> > 
> > I got the following error:
> > One or more output arguments not assigned during call to "varargout".
> > 
> > Error in PowerFlowCalculation (line 51)
> >         [x, y] = MyFunction(var1, var2, 'xxx');
> >
> > Can anyone give me hint? I really appreciate it, thank you!
> 
> What is nvargin?  I don't see it defined. I would have expected code something like this:
> 
>    if nargout < 2
>        varargout{1} = output1;
>    elseif nargout == 2
>        varargout{1} = output2, 
>        varargout{2} = output3;
>    else
>        error('Too many outputs');
>    end
> 
> 
> James Tursa

Hi, James, 

Thanks for your reply, it was my typo, it is nargin, the number of the input parameters. For others, please seem my reply to the next post as well, thank you!
0
MWei
10/1/2015 8:21:03 PM
"Steven Lord" <Steven_Lord@mathworks.com> wrote in message <mujjhv$6o0$1@newscl01ah.mathworks.com>...
> 
> 
> "MWei" <mingkui_wei@hotmail.com> wrote in message 
> news:muf2on$pbo$1@newscl01ah.mathworks.com...
> > I googled this error message and can not even find one that exactly match 
> > the whole sentence, am I the only person who get the error?
> >
> > I use Matlab 2015b to run a simulation, and I got this error message 
> > randomly during 1 of multiple same simulations.
> > My function is like the following:
> >
> > [varargout] = function MyFunction(var1, var2, varargin)
> 
> I assume this is a copy/paste error and that your function actually starts:
> 
> function varargout = MyFunction(var1, var2, varargin)
> 
> >  output1 = [xxx];
> >  output2 = [xxx];
> >  output3 = [xxx];
> >  ...
> >  varargout{1} = output1;
> >
> >  if nvargin > 2
> 
> This smells fishy. nvargin looks like it is probably a variable containing 
> the value returned by the NARGIN function or perhaps the value 
> length(varargin). Why are you only assigning a value to the second _output_ 
> based on the number of _inputs_?
> 
> if nargout > 1
>     varargout{2} = output3;
> end
> 
> *snip*
> 
> -- 
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on 
> http://www.mathworks.com 

Hi, Steve, 

Thanks for your reply. sorry I did make a few typos. It should be nargin, the number of input args, instead of nvargin. 

The reason I use narvin as the judgement is because I planned in a future version, I will always return 2 values, and the values differ based on the input args. For instance, if I call the function like MyFunction(1, 1), then it return [x1, y1], but if I call the function like this MyFunction(1, 1, 'other'), it will return [X1, Y1]. 

The thing that seems strange to me, is that usually if I do not assign enough value to varargout, it will give error: One or more output arguments not assigned during call to "MyFunction"

For example, if I input [a b c d]=plot(1,1), it will return: One or more output arguments not assigned during call to "plot".

But in my case, it says "during call to "varargout"", instead of "during call to "MyFunction"".   
0
MWei
10/1/2015 8:32:03 PM
Reply: