Re: bug in zeros and ones when "logical" class name is used




"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:

bw = zeros(size(5), class(logical(5)));
??? Error using ==> zeros
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


.



Relevant Pages

  • Re: Error code
    ... adding those 1 column matrix files, ... While combining three arrays with the command in matlab 7, ... with best Regards, ... By filling in zeros in the bottom of the shorter matrixes? ...
    (comp.soft-sys.matlab)
  • Re: COMMON structures and text parsing
    ... own code using integers as shadow logicals, ... I guess I did not say this before, but the compiler should complain ... enumerated type, and BOOLEAN is an enumerated type. ... arrays, where you can "index" an array with ...
    (comp.lang.fortran)
  • plot and subscript indices error
    ... Subscript indices must either be real positive integers or ... logicals. ... Both Time and BCIE are 1x63 double arrays, and all the entries in the ...
    (comp.soft-sys.matlab)
  • Re: How can i plot this??
    ... Ok let me refrase the question how can i reshape the arrays so the ... Otherwise if you fill y3 with zeros to force the same ...
    (comp.soft-sys.matlab)
  • Storing binary checkpoint data
    ... and two filled with logicals. ... Every 100 iterations, I want to dump these out into a file. ... I'd like to write these out in binary form, into a single file, but I can't ... figure out how to do make my data (several large arrays) chime with the ...
    (comp.lang.fortran)