Re: bug in zeros and ones when "logical" class name is used
- From: "Steven Lord" <slord@xxxxxxxxxxxxx>
- Date: Fri, 14 Nov 2008 10:32:55 -0500
"Pinpress" <nospam__@xxxxxxxxx> wrote in message
news:gfim16$puj$1@xxxxxxxxxxxxxxxxxxxxx
Hi all,
I believe the following error returned by matlab indicate bug(s) in
function zeros:
??? Error using ==> zerosbw = zeros(size(5), class(logical(5)));
Trailing string input must be a valid numeric class name.
If I used "ones", I had the same error. Anyone has met this before? If
class(logical(5))
returns "logical" as a class name, then "zeros" and "ones" should take it
as a valid class name as well for consistency.
This is not a bug. As the error message indicates, when you specify a class
name as the last input to the ZEROS function, it must be a valid numeric
class name. What are the valid numeric class names? Well, let's see what
ISNUMERIC, the function that tests if an array is numeric or not, says:
http://www.mathworks.com/access/helpdesk/help/techdoc/ref/isnumeric.html
"tf = isnumeric(A) returns logical 1 (true) if A is a numeric array and
logical 0 (false) otherwise. For example, sparse arrays and double-precision
arrays are numeric, while strings, cell arrays, and structure arrays and
logicals are not."
So "isnumeric(logical(5))" returns false, which means it is not a valid
numeric class name and so can't be used as the class input to ZEROS or ONES.
As Loren and others suggested, if you want to construct a large logical
array, you should use FALSE (to preallocate it filled with logical 0's) or
TRUE (to preallocate it filled with logical 1's.)
--
Steve Lord
slord@xxxxxxxxxxxxx
.
- References:
- bug in zeros and ones when "logical" class name is used
- From: Pinpress
- bug in zeros and ones when "logical" class name is used
- Prev by Date: filtering and aliasing
- Next by Date: Re: reading complex marix from file
- Previous by thread: Re: bug in zeros and ones when "logical" class name is used
- Next by thread: Isolation of audio channels left/right.
- Index(es):
Relevant Pages
|