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: Jordi Gutiérrez Hermoso
Subject: Re: cell{1:5}=1 not working for me!!!
Date: Thu, 31 May 2012 12:00:37 -0400

On 31 May 2012 11:37, oxy <address@hidden> wrote:
> Sorry, I have to reformulate:
>
> The thing is, I cannot initialize a multielement cell in 1-step as i
> can do with vectors:
>
> v(1:5)=7  % v was initialized here
>
> For a cell i need 2 steps:
> c={}
> c(1:5)=7     % c must be initialized first. Cant do it in 1 step
>
> Interestingly, global vectors must also be initialized first
> and then set:
>
>  global v(1:6)=9    % this will fail
>
> global v2
> v2(1:5)=7       % this will work

I'm not exactly sure what your plan is, but you can do something like

    global c = num2cell(repmat(1,5,7));

or

    global c = {7, 7, 7, 7, 7}

or

    global c = num2cell(7*ones(1,5))

I'm not sure if you count two function calls as one step or two,
though.

- Jordi G. H.


reply via email to

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