help-octave
[Top][All Lists]
Advanced

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

Re: Question about creating functions...


From: Juan Pablo Carbajal
Subject: Re: Question about creating functions...
Date: Thu, 7 Apr 2016 22:35:07 +0200

On Thu, Apr 7, 2016 at 5:36 PM, Del Ventruella <address@hidden> wrote:
> I'm new to Octave.  I learned Matlab many years ago, but two decades have
> passed.
>
> My initial attempts at writing functions follows.
>
> Can anyone give me some help with this file?
>
> Any pointers on functions and their inputs?
>
> I may want to use variables, as I do here, or I may want to use an array.
>
> Thanks!
> ======================
>
> #! C:\Octave\Octave-3.8.2\octave.bat -qf
> # a sample Octave program
> clc;
>
> function theta =thetaval(x)
> if (x < 0)
>    theta = 0;
> elsif (x > 0)
>    theta = 1;
> else
>    theta = 0.50;
> endif
> endfunction
>
> function delta = deltaval(a,x)
> delta = (a*sqrt(3.14159))^-1 * 2.7^(-y^2 / a^2);
> endfunction
>
> theta = cellfun(@thetaval,3)
> delta = cellfun(@deltaval,(2,5))
>
> printf ("theta = %10.2e \n",theta);
> printf ("delta = %10.4e \n",delta);
> # printf ("Hello, world!\n");
> pause;
> ans = input ("Press Enter to End");
>
>
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/help-octave
>

You do not need to use cellfun!
Just do
theta = thetaval(3)
delta = deltaval(2,5)



reply via email to

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