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: Ben Abbott
Subject: Re: foo_cs = foo{:} - feature or bug ? (octave-3.4.2); also, sizeof(foo{:})
Date: Mon, 08 Aug 2011 07:30:46 -0400

On Aug 8, 2011, at 6:37 AM, Sergei Steshenko wrote:

> Hello,
> 
> here is a screen session:
> 
> "
> 
> 
> octave:1> foo{1,1} = "a"
> foo =
> {
>  [1,1] = a
> }
> octave:2> foo{1,2} = "b"
> foo =
> {
>  [1,1] = a
>  [1,2] = b
> }
> octave:3> foo{2,1} = [1 2]
> foo =
> {
>  [1,1] = a
>  [2,1] =
> 
>     1   2
> 
>  [1,2] = b
>  [2,2] = [](0x0)
> }
> octave:4> foo_cs = foo{:}
> foo_cs = a
> octave:5> sizeof(foo{:})
> error: Invalid call to sizeof.  Correct usage is:
> 
> -- Built-in Function:  sizeof (VAL)
> 
> 
> Additional help for built-in functions and operators is
> available in the on-line version of the manual.  Use the command
> `doc <topic>' to search the manual index.
> 
> Help and information about Octave is also available on the WWW
> at http://www.octave.org and via the address@hidden
> mailing list.
> octave:5> sizeof(foo_cs)
> ans =  1
> octave:6> sizeof(1 + 2)
> ans =  8
> octave:7> sizeof(foo)
> ans =  18
> octave:8> 
> ".
> 
> Questions:
> 
> 1) why is it so that 'foo_cs' shows just one element (and its 'sizeof' is
> indeer 1 - see above) :

foo = {"a", "b"; [1 2], []}

On the command line, foo{:} is equivalent to typing the comma separated list 
below.

        "a", [1 2], "b", []

My impression is that you tried to create a comma-separated list (cs-list) 
object with your assignment ...

        foo_cs = foo{:}

However, cs-list objects do not exist at the command line. Meaning foo{:} 
creates a cs-list, but you cannot assign it to anything. However, you can store 
a cs-list in a cell array.

my_cell = {foo{:}}

Or you can parse it into multiple other objections using the deal() function.

>> [a,b,c,d] = deal (foo{:})
a = a
b =

   1   2

c = b
d = [](0x0)

> 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.

foo{:} is not an object, but a comma separated list of objects. When you type 
....

        sizeof (foo{:})

... you are implying ....

        sizeof ("a", [1 2], "b", [])

Each of these give the same error.

>> sizeof(foo{:})
error: Invalid call to sizeof.  Correct usage is:

 -- Built-in Function:  sizeof (VAL)


Additional help for built-in functions and operators is
available in the on-line version of the manual.  Use the command
`doc <topic>' to search the manual index.

Help and information about Octave is also available on the WWW
at http://www.octave.org and via the address@hidden
mailing list.
>> sizeof ("a", [1 2], "b", [])
error: Invalid call to sizeof.  Correct usage is:

 -- Built-in Function:  sizeof (VAL)


Additional help for built-in functions and operators is
available in the on-line version of the manual.  Use the command
`doc <topic>' to search the manual index.

Ben





reply via email to

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