help-octave
[Top][All Lists]
Advanced

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

Re: help how do I multiply a scalar by a cell (element) and store in a s


From: Max Brister
Subject: Re: help how do I multiply a scalar by a cell (element) and store in a scalar
Date: Sun, 9 Sep 2012 15:04:13 -0600

On Sun, Sep 9, 2012 at 2:59 PM, Jordi GutiƩrrez Hermoso
<address@hidden> wrote:
> On 9 September 2012 16:37, Jerry Baucum <address@hidden> wrote:
>> Sample =
>> {
>>   [1,1] = -0.12300
>>   [1,2] =  0.23400
>> }
>>
>> value = pi * Sample(1,2)
>>
>> I'm running up against the error
>>
>> error: binary operator `*' not implemented for `scalar' by `cell' operations
>
> Do you really want a cell array and not a matrix?
>
> If so, do
>
>     cellfun(@times, c, {5}, 'Unif', false)
>
> Otherwise, use matrices:
>
>     Sample = [0.12; 0.34];
>     5*Sample
>
> HTH,
> - Jordi G. H.

Alternatively, you can use curly braces for indexing. From you original example,

Sample =
{
  [1,1] = -0.12300
  [1,2] =  0.23400
}
value = pi * Sample{1, 2}

As Jordi suggested, matrices are a better option if your Sample array
is uniformly real.

-- 
Max Brister


reply via email to

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