From: Hugo on 11 Jun 2010 23:28 Hi. I wanted to know if I can initialize a variable in MATLAB, say var, so I can get the following result: % size(var) ans 0 0 % This question came to my mind when I realized that varargin (variable length input argument list) can actually throw this result! Many thanks in advance. PS: Any comment regarding this subject will be greatly appreciated.
From: Hugo on 11 Jun 2010 23:57 Sorry! This was not what I wanted to ask... my apologies... My question is: if I can initialize a variable, say var, so I can get nothing when I type it in the prompt: % var % (I mean without answer)... as the same way one can get with varargin when its list is empty. Many thanks in advance.
From: Walter Roberson on 12 Jun 2010 00:07 Hugo wrote: > Sorry! This was not what I wanted to ask... my apologies... > > My question is: if I can initialize a variable, say var, so I can get > nothing when I type it in the prompt: > % var > % > > (I mean without answer)... as the same way one can get with varargin > when its list is empty. No, there is no way. The reason that varargin returns nothing at all when you use it at the command prompt is that varargin.m is a script that contains nothing but comments, and is thus the same thing as typing a bunch of comments at the command prompt. varargin used within a routine does not return nothing: Put the below into testvar.m function testvar(varargin) varargin end Then at the command prompt, >> testvar varargin = {}
From: Matt Fig on 12 Jun 2010 01:12 I am not sure why you would want to do this, but you could mimic the behavior you want by defining a function instead of a variable. For example: function A = v() if nargout A = 3; end Now from the command line: >> v >> 5*v ans = 15 >> v^2 ans = 9 >> v >>
From: John D'Errico on 12 Jun 2010 04:29
"Hugo " <hresquiveloa(a)gmail.com> wrote in message <huuus4$pup$1(a)fred.mathworks.com>... > Hi. I wanted to know if I can initialize a variable in MATLAB, say var, so I can get the following result: > % size(var) > ans > 0 0 > % > > This question came to my mind when I realized that varargin (variable length input argument list) can actually throw this result! > > Many thanks in advance. > > PS: Any comment regarding this subject will be greatly appreciated. Easy, peasy. A = zeros(0,0); size(A) ans = 0 0 HTH, John |