[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Trouble Using Functions
From: |
Andrew Janke |
Subject: |
Re: Trouble Using Functions |
Date: |
Wed, 24 Jun 2020 15:44:27 -0400 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 |
On 6/24/20 3:28 PM, Samuel Doughty wrote:
> I've written a short script to use functions, and it does not run for me
> (it says the first function encountered is not defined). Any help would
> be appreciated. Here is my script:
>
> % TestFile1
> p=[1;2;3]
> q=[3;4;7]
> ssq=s2(q);
> [add,subt]=s1(p,q);
>
> function [sum,diff]=s1(a,b)
> print " Function s1 -- sum and difference"
> sum=a+b
> diff=a-b
> endfunction
> function sumsq=s2(a)
> print " Function s2 -- sum of squares"
> sumsq=a'*a
> endfunction
>
Hi Sam,
That's in Matlab format, where local functions go at the end of a
script. In Octave, functions inside a script need to come before they
are used.
Cheers,
Andrew