Octave Commands Cheat Sheet



  1. Octave Commands Cheat Sheet Printable
  2. Octave Commands Cheat Sheet Download
  3. Octave Commands Cheat Sheet
  4. Octave Commands Cheat Sheet Free
  5. Octave Commands Cheat Sheet Pdf

To have Octave read and compile these functions into an internal form, you need to make sure that the file is in Octave’s load path (accessible through the path function), then simply type the base name of the file that contains the commands. (Octave uses the same rules to search for script files as it does to search for function files.). Go through the provided Octave cheat sheet and try out the di erent commands. Ask for help whenever you need it. As pointed out in the sheet, a very useful Octave command is help. Use it to get information about the correct way to call any Octave function. Exercise 2: Implementing an odometry model.

Next: Function Handles Anonymous Functions Inline Functions, Previous: Function Files, Up: Functions and Scripts [Contents][Index]

11.10 Script Files

A script file is a file containing (almost) any sequence of Octavecommands. It is read and evaluated just as if you had typed eachcommand at the Octave prompt, and provides a convenient way to perform asequence of commands that do not logically belong inside a function.

Unlike a function file, a script file must not begin with thekeyword function. If it does, Octave will assume that it is afunction file, and that it defines a single function that should beevaluated as soon as it is defined.

A script file also differs from a function file in that the variablesnamed in a script file are not local variables, but are in the samescope as the other variables that are visible on the command line.

Even though a script file may not begin with the functionkeyword, it is possible to define more than one function in a singlescript file and load (but not execute) all of them at once. To dothis, the first token in the file (ignoring comments and other whitespace) must be something other than function. If you have noother statements to evaluate, you can use a statement that has noeffect, like this:

To have Octave read and compile these functions into an internal form,you need to make sure that the file is in Octave’s load path(accessible through the path function), then simply type thebase name of the file that contains the commands. (Octave uses thesame rules to search for script files as it does to search forfunction files.)

If the first token in a file (ignoring comments) is function,Octave will compile the function and try to execute it, printing amessage warning about any non-whitespace characters that appear afterthe function definition.

Note that Octave does not try to look up the definition of any identifieruntil it needs to evaluate it. This means that Octave will compile thefollowing statements if they appear in a script file, or are typed atthe command line,

even though the function do_something is not defined before it isreferenced in the function foo. This is not an error becauseOctave does not need to resolve all symbols that are referenced by afunction until the function is actually evaluated.

Since Octave doesn’t look for definitions until they are needed, thefollowing code will always print ‘bar = 3’ whether it is typeddirectly on the command line, read from a script file, or is part of afunction body, even if there is a function or script file calledbar.m in Octave’s path.

Code like this appearing within a function body could fool Octave ifdefinitions were resolved as the function was being compiled. It wouldbe virtually impossible to make Octave clever enough to evaluate thiscode in a consistent fashion. The parser would have to be able toperform the call to eval at compile time, and that would beimpossible unless all the references in the string to be evaluated couldalso be resolved, and requiring that would be too restrictive (thestring might come from user input, or depend on things that are notknown until the function is evaluated).

Although Octave normally executes commands from script files that havethe name file.m, you can use the function source toexecute commands from any file.

: source(file)
Octave commands cheat sheet
: source(file, context)

Parse and execute the contents of file.

Without specifying context, this is equivalent to executing commandsfrom a script file, but without requiring the file to be namedfile.m or to be on the execution path.

Instead of the current context, the script may be executed in either thecontext of the function that called the present function('caller'), or the top-level context ('base').

Octave Commands Cheat Sheet

See also:run.

• Publish Octave Script Files:
• Publishing Markup:

Next: Function Handles Anonymous Functions Inline Functions, Previous: Function Files, Up: Functions and Scripts [Contents][Index]

Octave Statistics Tips


Refer to the Octave on-line help for a full description of an Octave command. For example, to find out more about boxplots type:

Octave Commands Cheat Sheet


help boxplot


Reading A Dataset

Browse to C:optoctaveengr390ASCII. You should see several folders. Each folder corresponds to a chapter in the book. Folder CH01 contains all of the datasets from chapter 1. In the CH01 folder you will see datasets for both the examples and the exercises. The example dataset file names start with “exp” while the exercise dataset file names start with “ex”.


Exercise 1.11 contains a single set of test scores. To read the scores into an array use:


scores = readdataset('ch01/ex01-11.txt');


Exercise 1.66 contains five sets of data, use the following command to read in all five data sets (into array variables d1 through d5):


[d1 d2 d3 d4 d5] = readdataset('ch01/ex01-66');


Basic Statistical Commands

n = length(x); % number of observations in dataset

y =sort(x); % sort the observations

sum(x > 100 & x <= 150) % display the number of observations between 100 and 150

m = mean(x); % sample mean

med = median(x); % sample median

Octave Commands Cheat Sheet

s = std(x); % sample standard deviation

Octave Commands Cheat Sheet Printable

v = var(x); % sample variance

x25 = prctile(x, 25); % 25th percentile (Octave definition)

x25 = quantile(x, 0.25); % 25th percentile (text definition)

xtr10 = trimmean(x, 10); % 10% trimmed mean

Octave Commands Cheat Sheet Download


Statistical Plots

hist(x) % 10 bins equally spaced between min and max

Octave

Octave Commands Cheat Sheet

hist(x, 500:1000:5500) % bins centered at 500, 1500, 2500, …, 5500

hist(x, 500:1000:5500, 1) % relative freq. histogram (bar heights sum to 1)

histpdf(x) % histogram normalized for unit area

boxplot(x, 0, 'xo', 0) % boxplot with outliers (similar to the boxplots in the text)


Octave Commands Cheat Sheet Free


Octave Commands Cheat Sheet Pdf