The Mac Observer

 
   
 
Matlab/Octave Function declaration?
Posted: 25 February 2002 06:12 AM [ Ignore ]
stars_5
Total Posts:  1162
Joined  2001-11-02

Has anyone done much programming in Matlab (more specifically Octave, but they should be more or less identical)

how the hell do you declare multiple functions in the same file!

function () () end
          
function () () end
          
function () nargin == || error ("nargin != 1"); end 

Put this in a file named f.m It compiles f, but then sees g as unknown.  you can’t put g in front of f because then it isn’t named properly for the file, and if you put the end for function f at the end of the entire file (as I thought you were supposed) octave spits back an error saying you can’t declare a function inside a function (kind of makes sense).  I can’t even find a good example program with two functions in one file.  All of the Octave builtin examples contain one function per file! (at least all the ones I looked at.) 

grrr, I want to go back to IDL. 

little help? 

 Signature 

All statements are to be taken with a grain of salt

Profile
 
 
Posted: 25 February 2002 12:27 AM [ Ignore ] [ # 1 ]
Moderator
Total Posts:  3912
Joined  2001-07-13

On 2002-02-25 03:46, EDGar wrote:
Has anyone done much programming in Matlab (more specifically Octave, but they should be more or less identical)

how the hell do you declare multiple functions in the same file!

function () () end
          
function () () end
          
function () nargin == || error ("nargin != 1"); end 

Put this in a file named f.m It compiles f, but then sees g as unknown.  you can’t put g in front of f because then it isn’t named properly for the file, and if you put the end for function f at the end of the entire file (as I thought you were supposed) octave spits back an error saying you can’t declare a function inside a function (kind of makes sense).  I can’t even find a good example program with two functions in one file.  All of the Octave builtin examples contain one function per file! (at least all the ones I looked at.) 

EDGar, I’m sure there is a reason in your specific code, but why can’t you simply do somethin like this:

function () () end
          
function () nargin == || error ("nargin != 1"); end 

and forget the “function g ()” altogether? Or is the “function g ()” there for a specific reason?

grrr, I want to go back to IDL. 

I can certainly understand that ...

 

 

 Signature 

Work is the curse of the drinking classes.
- Oscar Wilde

Profile
 
 
Posted: 25 February 2002 05:54 AM [ Ignore ] [ # 2 ]
stars_5
Total Posts:  1162
Joined  2001-11-02

no, g() isn’t there for a particular reason, but it also shouldn’t matter.  I grabbed that example straight out of a help manual, and it works fine at the command line because it doesn’t actually call f() at first it just declares it, then by the time I call it I have also declared g() and h() so it has no problem.  So… maybe what I am really after is a way to compile a file before running it.

<smacks forehead> I’ll RTFM again.  If anyone knows how off the top of their head let me know.  In Matlab I think there is a GUI option compile.  is there a command line option to compile too? 

something like IDL’s .compile functionality? 

 Signature 

All statements are to be taken with a grain of salt

Profile
 
 
Posted: 25 February 2002 06:12 AM [ Ignore ] [ # 3 ]
Moderator
Total Posts:  3912
Joined  2001-07-13

Glad to help. I know nothing about Matlab, but I know a lot of languages, and I also know that getting someone to talk out loud is often the best; the person will figure it out on his own. “Self-debugging”, a friend calls it.

 

 Signature 

Work is the curse of the drinking classes.
- Oscar Wilde

Profile
 
 
   
 
 

Apple Stock Quote (AAPL)

Loading...

Hot Topics

TMO Express

Join the TMO Express Daily Newsletter to get the latest Mac headlines in your e-mail every weekday. Find out more!

Top Deals From DealBrothers.com

Recent Features

Support The Mac Observer

We noticed you may be running AdBlock on your computer. It takes real money to run this site and to deliver the news, tips, and opinions you love to read.

If you wish to block the ads that pay for the creation of our content, we ask that you instead support TMO Directly, either with a $5 monthly recurring contribution, or a one-time donation of any amount of your choice. Thanks!

Subscribe with Paypal Donate with Paypal