help-octave
[Top][All Lists]
Advanced

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

Re: Apply function to vector


From: Jordi Gutiérrez Hermoso
Subject: Re: Apply function to vector
Date: Mon, 20 Jun 2011 09:30:02 -0500

On 20 June 2011 04:59, Fritz Fischer <address@hidden> wrote:
> For convenient reasons to plot functions I would like to apply a function to
> a vector:
>
> e.g.
>
> x = 0:1:2*pi
> y = sin(x)
> plot(x,y)
>
> So far, everything works fine.
> But if I want to apply one of my functions the same way,
> e.g.
>
> x = 0:1:40
> y = rayleigh_optical_density(x) %contains just some simple calculations
>
> I get the following message:
>
> error: for A^b, A must be square
>
> I read about element-wise operations, but I guess this is of no use here,
> isn't it?

It depends how you wrote rayleigh_optical_density. Did you vectorise
it? What functions does it call? You need to either rewrite it to use
elementwise calculations or to call arrayfun on it:

     arrayfun(@rayleigh_optical_density, x)

HTH,
- Jordi G. H.


reply via email to

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