Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is no really good answer at the current time. If you want to just define a simple variable that is seen in your workspace, then</p> <p>f00 = 88;</p> <p>obviously works. But this will not be seen inside other functions. So you could define it as a global variable, but then you need to declare each variable as global inside every function that will need it. To me this seems a kludge. Slightly better IMHO, is to define a function m-file for foo.</p> <pre><code>function returnvalue = f00 % returns the scalar value of 88 returnvalue = 88; </code></pre> <p>(Note that I have a comment line here. This is returned when you call help foo, as well, lookfor will see that line too. Better help than this is recommended, but I am feeling lazy right now.)</p> <p>As long as foo.m is on your search path, then this always returns the value 88. Note that I have included no arguments. But you could be more creative, and perhaps allow a size argument, so that foo(N) would behave as do zeros, ones and eye. This is the nice thing about using a function here. It can do exactly as you wish. So perhaps...</p> <pre><code>function returnvalue = f00(varargin) % returns the scalar value of 88, or replicated elements if a size is supplied % usage: foo % usage: foo(N) % usage: foo(N1,N2,...) % % arguments: % N - a scalar or vector that denotes the number % of repeated elements (all 88) to be generated % % returnvalue - a scalar (or vector/array) of % size indicated by N. % % see also: ones, zeros, eye if (nargin == 0) % no arguments, so return a scalar 88 returnvalue = 88; elseif (nargin == 1) &amp;&amp; isscalar(varargin{1}) % be consistent with ones, zeros, eye, etc. returnvalue = repmat(88,[varargin{1},varargin{1}]); elseif (nargin == 1) % the size is a vector already if isvector(varargin{1}) returnvalue = repmat(88,varargin{1}); else error('FOO:impropersize','Size argument cannot be a general array') end elseif % nargin must have been more than 1 returnvalue = repmat(88,cell2mat(varargin)); end </code></pre> <p>I could probably do a bit better error checking above, but you should get the general idea.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload