error to compile function

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

error to compile function

LucaLuca
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


is it logical to receive errors in compiling functions where I do not pass
any parameters?






--
Sent from: http://octave.1599824.n4.nabble.com/Octave-Maintainers-f1638794.html

Reply | Threaded
Open this post in threaded view
|

Re: error to compile function

Mike Miller-4
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 (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: error to compile function

LucaLuca
In reply to this post by LucaLuca
Hi thank

It is possible only compile it? In gui octave i dont find it
(I see only save and run)



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-Maintainers-f1638794.html

Reply | Threaded
Open this post in threaded view
|

Re: error to compile function

Richard Crozier


On 26/06/18 16:11, Luca Salardi wrote:

> Hi thank
>
> It is possible only compile it? In gui octave i dont find it
> (I see only save and run)
>
>
>
> --
> Sent from: http://octave.1599824.n4.nabble.com/Octave-Maintainers-f1638794.html
>


Octave is an interpreted language, you don't compile it, you just write
the function then you run it. I would suggest directing your questions
to [hidden email] instead of this mailing list as this mailing list is
about development of Octave, rather than for help using it. You will
find you get more help there. I also suggest you have a look at this page:

https://www.gnu.org/software/octave/support.html

Which has more places to get help to start using Octave.

Good luck!

Richard

--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.