[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: a{:} = x
From: |
John W. Eaton |
Subject: |
Re: a{:} = x |
Date: |
Mon, 12 Jan 2009 01:23:01 -0500 |
On 11-Jan-2009, Jaroslav Hajek wrote:
| On Fri, Jan 9, 2009 at 5:50 PM, John W. Eaton <address@hidden> wrote:
| > 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}
| >
|
| Agreed.
|
|
| > | 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.
|
| Why? Isn't it better to give an error message?
| In Matlab 2007, the following code:
|
| x = 1,2,3
|
| produces
|
| x = 1
| ans = 2
| ans = 3
|
| whereas
|
| y = {1,2,3}; x = {:}
|
| produces just
|
| x = 1
|
| Which behaviour is correct? I think y{:} is supposed to be equivalent
| to y{1},y{2},y{3}, but apparently it is not.
Yeah, although normaly a comma-separated list works like a list of
values separated by commas, these commas must be different. :-/
I suppose it makes sense if you think about the comma that is a
statement separator as being different from the comma that is to
separate the elements of an argument list. But hmm. That just makes
things more confusing in a way.
| behavior a little more, but I'd apreciate even more a message like
| this:
| error: the number of rhs values does not match lhs
I think that would be reasonable. Does any real code actually depend
on this "feature"?
| I've uploaded a patch fixing the a{x:y} = z case. Note that the
| incorrect idiom was used in a number of places within Octave's
| m-sources, so I guess this may reveal bugs in OctaveForge as well.
|
| http://hg.savannah.gnu.org/hgweb/octave/rev/fd11a08a9b31
Thanks.
| The other stuff like the "a = 1,2,3" case is left intact, but I'd like
| if someone explained the logic of the current behaviour to me.
It is just three separate expressions, separated by commas. So it is
equivalent to
a = 1
2
3
jwe
- a{:} = x, Jaroslav Hajek, 2009/01/09
- a{:} = x, John W. Eaton, 2009/01/09
- Message not available
- Re: a{:} = x,
John W. Eaton <=
- Re: a{:} = x, Jaroslav Hajek, 2009/01/12
- Message not available
- Message not available
- Re: a{:} = x, John W. Eaton, 2009/01/12