help-octave
[Top][All Lists]
Advanced

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

Re: cell{1:5}=1 not working for me!!!


From: c.
Subject: Re: cell{1:5}=1 not working for me!!!
Date: Wed, 30 May 2012 17:46:32 +0200

On 30 May 2012, at 17:36, oxy wrote:

> And why a cell cannot be initialized as global?
> 
> octave:12> global p
> octave:13> p(1:5)={3}
> error: operator =: no conversion for assignment of `cell' to indexed `matrix'
> error: assignment failed, or no method for `matrix = cell'

a global variable can indeed be initialized to be a cell array

>> global p = cell(1, 5)
>> p(1:5) = 3;
>> p
p = 
{
  [1,1] =  3
  [1,2] =  3
  [1,3] =  3
  [1,4] =  3
  [1,5] =  3
}


The error message you show above does not complain about p being global
it tells you that the syntax used by the assignment on line 13 is nonsense. 

Your syntax is interpreted as trying to resize p to be a 1x5 matrix and then 
assigning 
a 1x1 cell-array containing the scalar value 3 to each element of the matrix, 
which is not
possibe, hence the error.

The error message seems quite clear to me, why did you think it was related to 
the fact that p is declared global?

c.

reply via email to

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