[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: error to compile function
From: |
Mike Miller |
Subject: |
Re: error to compile function |
Date: |
Sun, 24 Jun 2018 11:14:08 -0700 |
User-agent: |
Mutt/1.10.0 (2018-05-17) |
On Sat, Jun 23, 2018 at 10:43:04 -0700, Luca Salardi wrote:
> hi,
> i write this code:
>
> function eserciziFunzioni2=mini(x)
> eserciziFunzioni2 = x(1);
> for i=2:length(x),
> if x(i) < eserciziFunzioni2
> eserciziFunzioni2 = x(i);
> end;
> end;
> endfunction
>
>
> i try do compile it i receive this error:
>
> >> eserciziFunzioni2
>
> error: 'x' undefined near line 2 column 24
> error: called from
> eserciziFunzioni2 at line 2 column 22
There are a couple of fundamental problems with this example. You seem
to be confusing the name of the function with the return value. If you
want the function to be called 'eserciziFunzioni2', that name should
come after the equal sign.
For example
function answer = squared (x)
answer = x .^ 2;
endfunction
a = squared (5)
You should probably review this section of the user manual
https://octave.org/doc/interpreter/Defining-Functions.html
> is it logical to receive errors in compiling functions where I do not pass
> any parameters?
If you mean 'calling a function' instead of 'compiling', yes it is the
correct behavior to get an error if you don't supply the expected
arguments.
--
mike
signature.asc
Description: PGP signature