octave-maintainers
[Top][All Lists]
Advanced

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

a{:} = x


From: John W. Eaton
Subject: a{:} = x
Date: Fri, 9 Jan 2009 11:50:46 -0500

On  9-Jan-2009, Jaroslav Hajek wrote:

| I just noticed that the following code works in Octave:
| a = {1,2,3}
| a{:} = 1
| and ends up with a = {1,1,1}. Matlab gives an error? Extension or bug?

I think the correct way to place a particular value in each cell would
be

  a(:) = {1}

| What's more weird,
| a{:} = a{:} works as well and likewise gives a = {1,1,1}.

IF a{:} = 1 is accepted, then I think this sort of makes sense because
a{:} produces a comma-separated list, so a{:} = a{:} would be
equivalent to

  a{:} = 1, 2, 3

But then, you should also see the 2, 3 results printed to the screen.

3.0.3 gives an error for a{:} = a{:}.

We should probably also have errors for a{:} = scalar if A has more
than one element.  Having an error makes some sense because if a{:} is
used on the LHS of an assignment, I think it should only be in
expressions like

  [a{:}] = ...

and for that to work, the RHS should produce enough values to satisfy
the LHS.

What about the case of a(:) = 1?  Should that be an error?

jwe


reply via email to

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