help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: foo_cs = foo{:} - feature or bug ? (octave-3.4.2); also, sizeof(foo{


From: James Sherman Jr.
Subject: Re: foo_cs = foo{:} - feature or bug ? (octave-3.4.2); also, sizeof(foo{:})
Date: Mon, 8 Aug 2011 07:35:22 -0400


1) why is it so that 'foo_cs' shows just one element (and its 'sizeof' is
indeer 1 - see above) :

"
octave:4> foo_cs = foo{:}
foo_cs = a
"
?
sizeof doesn't return the number of elements, it is the number of bytes of that variable.  Since foo_cs has a value of "a", you're asking it for the size of one character, which is indeed 1.

 
2) why "sizeof(foo{:})" refuses to work while "sizeof(1 + 2)" and
"sizeof(foo)" work ? I think "foo{:}" occupies some bytes in memory, so
'sizeof' taking it as its argument should make sense.

sizeof(foo{:}) is equivalent to typing out sizeof(foo{1}, foo{2}), just like in your previous experience with numel  (i.e. numel(foo{:}) is the same as numel(foo{1}, foo{2}) ).  In this case, sizeof is a function that only takes one argument, thus produces an error.

Note that when you typed:
foo_cs = foo{:}
is equivalent to typing:
foo_cs = foo{1},foo{2}
which means that foo_cs really only contains the first element, and the second doesn't get assigned to anything.

Hope this helps.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]