Discussion:
Saving Programs in Octave
(too old to reply)
d***@gmail.com
2009-01-29 14:45:08 UTC
Permalink
Hi,

I am a complete beginner trying (struggling!) to deal with Octave on
Mac OS X. I have some experience in C, so explanations in comparison
to C if possible, would be helpful.

How to do you start writing a program (are these what many help
documents are calling 'executable programs'?) in Octave? I can fiddle
around with various functions and things but I would like to combine
them into a program. Perhaps if you could give me an example or a
sample program code I would be able to understand better. I can't seem
to find one even though I've been searching for a week. Then how would
you save the program and then load it? When I wrote in C, if you
loaded a program it would display the entire code for the program -
surely I should be able to achieve the same with Octave...?

Also, when you use the save function, e.g. save a, where a is a
variable, it just saves it under my Home folder. How can I define the
path so it saves it elsewhere, a folder inside my Documents folder?

Thank you so much! I'm so frustrated because even though I can create
and use functions I have no idea how to use them by writing them into
a program. Does each function have to saved separately as an .m file?

Again, thank you all, I really look forward to any words of help and
advice!

Cheers,
Danbee
Tim Love
2009-01-29 16:28:57 UTC
Permalink
Post by d***@gmail.com
Hi,
How to do you start writing a program (are these what many help
documents are calling 'executable programs'?)
You just create a text file containing the kind of lines that
work from the octave command line. If you call the file "cabbage.m"
then you run it by typing cabbage from the octave prompt.
I use emacs to create the files.
The files need to be created where Octave will look for them.
Type
path
in octave to find out where octave looks by default.
Post by d***@gmail.com
Also, when you use the save function, e.g. save a, where a is a
variable, it just saves it under my Home folder. How can I define the
path so it saves it elsewhere, a folder inside my Documents folder?
Type
help save
Post by d***@gmail.com
Does each function have to saved separately as an .m file?
If octave's like matlab in this respect, you can have many, but only
one is callable from outside the file.
d***@gmail.com
2009-01-31 07:51:47 UTC
Permalink
Thanks!

I have now fiddled around with Emacs, but still really confused.

How do you use the scanf function in Octave? I want to prompt a user
to give an input and store it in a variable. I have:

global x0
printf ("Enter initial x-coordinate: ")
scanf ("%d", x0)
printf ("\nThe initial x-coordinate is %d.\n", x0)

There obviously are many problems with that - but I don't know what!
How can I get the program to wait for an input after the printf, then
read it using scanf? Also, why can't I use tabs to indent in an m
file?

Thank you so much - I think I really need step by step help with
Octave! Thanks for being so patient.
d***@gmail.com
2009-01-31 16:41:47 UTC
Permalink
Post by d***@gmail.com
Thanks!
I have now fiddled around with Emacs, but still really confused.
How do you use the scanf function in Octave? I want to prompt a user
global x0
printf ("Enter initial x-coordinate: ")
scanf ("%d", x0)
printf ("\nThe initial x-coordinate is %d.\n", x0)
There obviously are many problems with that - but I don't know what!
How can I get the program to wait for an input after the printf, then
read it using scanf? Also, why can't I use tabs to indent in an m
file?
Thank you so much - I think I really need step by step help with
Octave! Thanks for being so patient.
Ah, I've managed to solve my own problem - instead of the printf,
scanf combination, I've learned to just use

variable = input ("message to be displayed")

Yay!

Loading...